Prev: INVITATION COMING OUT OF ENVELOPE
Next: Powerpoint 2007 links change from drive letters to UNC paths
From: Lester Lane on 16 Apr 2010 11:45 Hi, I have the classic case of code working in step mode but not when run. I have deliberately bound late to Word. I have even waited to check Word has loaded and is ready but still I get the dreaded 462 error on line with ##. Any help would be great as I am going round in circles. Needless to say that if Word opens ok whilst stepping through (and I had to pause a while before loading the dialog) then the code will run fine until I close that version of Word. Not knowing how to "Wait"/"Sleep" for 2 secs in code I added the test GetObject. Even tho' this returns ok the .Activate fails. Thanks in advance. Dim objWordApp As Object Dim rsLetterData As DAO.Recordset Dim qdfLetterData As DAO.QueryDef Dim strTemplate As String Dim i As Integer Dim intLength As Integer On Error GoTo ErrTrap Set qdfLetterData = db.QueryDefs("rsqryLetterData") qdfLetterData![FacilityID] = FacilityID Set rsLetterData = qdfLetterData.OpenRecordset With rsLetterData If Not .EOF Then 'Is an instance of Word already open that we can bind to? On Error Resume Next Set objWordApp = GetObject(, "Word.Application") On Error GoTo ErrTrap If objWordApp Is Nothing Then 'Word isn't already running - create a new instance... Set objWordApp = CreateObject("Word.Application") objWordApp.Visible = True Else End If On Error Resume Next Set objWordApp = GetObject(, "Word.Application") Do Until Err.Number = 0 Set objWordApp = GetObject(, "Word.Application") Loop On Error GoTo ErrTrap ## Tasks(objWordApp).Activate With Dialogs(wdDialogFileNew) If .Display = -1 Then 'clicked ok strTemplate = .Template Else MsgBox "No Template chosen", vbCritical, "No Template" Exit Function End If End With ....... End Function
From: Lester Lane on 16 Apr 2010 11:55 On 16 Apr, 16:45, Lester Lane <ja...(a)pigottsinvestments.co.uk> wrote: > Hi, I have the classic case of code working in step mode but not when > run. I have deliberately bound late to Word. I have even waited to > check Word has loaded and is ready but still I get the dreaded 462 > error on line with ##. Any help would be great as I am going round in > circles. Needless to say that if Word opens ok whilst stepping > through (and I had to pause a while before loading the dialog) then > the code will run fine until I close that version of Word. Not > knowing how to "Wait"/"Sleep" for 2 secs in code I added the test > GetObject. Even tho' this returns ok the .Activate fails. Thanks in > advance. > > Dim objWordApp As Object > Dim rsLetterData As DAO.Recordset > Dim qdfLetterData As DAO.QueryDef > Dim strTemplate As String > Dim i As Integer > Dim intLength As Integer > > On Error GoTo ErrTrap > Set qdfLetterData = db.QueryDefs("rsqryLetterData") > qdfLetterData![FacilityID] = FacilityID > Set rsLetterData = qdfLetterData.OpenRecordset > > With rsLetterData > If Not .EOF Then > > 'Is an instance of Word already open that we can bind to? > On Error Resume Next > Set objWordApp = GetObject(, "Word.Application") > On Error GoTo ErrTrap > > If objWordApp Is Nothing Then > 'Word isn't already running - create a new instance... > Set objWordApp = CreateObject("Word.Application") > objWordApp.Visible = True > Else > End If > > On Error Resume Next > Set objWordApp = GetObject(, "Word.Application") > Do Until Err.Number = 0 > Set objWordApp = GetObject(, "Word.Application") > Loop > On Error GoTo ErrTrap > > ## Tasks(objWordApp).Activate > With Dialogs(wdDialogFileNew) > If .Display = -1 Then 'clicked ok > strTemplate = .Template > Else > MsgBox "No Template chosen", vbCritical, "No Template" > Exit Function > End If > End With > ...... > End Function UPDATE: Now using a wait routine and still no joy unless I step through the code.. WaitFor = 2 Start = Timer While Timer < Start + WaitFor DoEvents Wend
From: Steve Rindsberg on 16 Apr 2010 16:40
Seems like you might want to post this in the appropriate Access and Word groups rather than in Powerpoint. If anybody here has the answer, they'll probably pipe up, of course, but you're more likely to find bodies WITH the answer in a more related group. In article <ce8d5b44-b364-42a9-809f- ce6a0c9464b2(a)s9g2000yqa.googlegroups.com>, Lester Lane wrote: > Hi, I have the classic case of code working in step mode but not when > run. I have deliberately bound late to Word. I have even waited to > check Word has loaded and is ready but still I get the dreaded 462 > error on line with ##. Any help would be great as I am going round in > circles. Needless to say that if Word opens ok whilst stepping > through (and I had to pause a while before loading the dialog) then > the code will run fine until I close that version of Word. Not > knowing how to "Wait"/"Sleep" for 2 secs in code I added the test > GetObject. Even tho' this returns ok the .Activate fails. Thanks in > advance. > > Dim objWordApp As Object > Dim rsLetterData As DAO.Recordset > Dim qdfLetterData As DAO.QueryDef > Dim strTemplate As String > Dim i As Integer > Dim intLength As Integer > > On Error GoTo ErrTrap > Set qdfLetterData = db.QueryDefs("rsqryLetterData") > qdfLetterData![FacilityID] = FacilityID > Set rsLetterData = qdfLetterData.OpenRecordset > > With rsLetterData > If Not .EOF Then > > 'Is an instance of Word already open that we can bind to? > On Error Resume Next > Set objWordApp = GetObject(, "Word.Application") > On Error GoTo ErrTrap > > If objWordApp Is Nothing Then > 'Word isn't already running - create a new instance... > Set objWordApp = CreateObject("Word.Application") > objWordApp.Visible = True > Else > End If > > On Error Resume Next > Set objWordApp = GetObject(, "Word.Application") > Do Until Err.Number = 0 > Set objWordApp = GetObject(, "Word.Application") > Loop > On Error GoTo ErrTrap > > ## Tasks(objWordApp).Activate > With Dialogs(wdDialogFileNew) > If .Display = -1 Then 'clicked ok > strTemplate = .Template > Else > MsgBox "No Template chosen", vbCritical, "No Template" > Exit Function > End If > End With > ....... > End Function ============================== PPT Frequently Asked Questions http://www.pptfaq.com/ PPTools add-ins for PowerPoint http://www.pptools.com/ |