![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) * * Dim obj As Object * * Dim strApp As String * * If vApp = 1 Then strApp = "Excel" Else strApp = "Word" * * On Error Resume Next * * * * Set obj = GetObject(, strApp & ".Application") * * * * If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") * * On Error GoTo ErrorOfficeApp * * obj.Visible = True * * obj.WindowState = 1 * * '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane |
#3
| |||
| |||
|
|
I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane |
#4
| |||
| |||
|
|
I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) * * Dim obj As Object * * Dim strApp As String * * If vApp = 1 Then strApp = "Excel" Else strApp = "Word" * * On Error Resume Next * * * * Set obj = GetObject(, strApp & ".Application") * * * * If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") * * On Error GoTo ErrorOfficeApp * * obj.Visible = True * * obj.WindowState = 1 * * '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane |
#5
| |||
| |||
|
|
-- "James A. Fortune" <CDMAPos... (AT) FortuneJames (DOT) com> wrote in messagenews:1a273c7f-6ffa-45df-bdf5-d4f23a0820a2 (AT) g26g2000vbz (DOT) googlegroups.com... On Dec 18, 10:13 pm, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane Here's some code I use to open an Excel "Template" that contains all the formatting, etc. that I want: Set objXL = CreateObject("Excel.Application") Set wbk = objXL.Workbooks.Open(strTemplate) wbk.SaveAs strFQP DoEvents 'Give the OS 1.5 seconds to save the copy Call MilliSleep(1500) objXL.Visible = True Set wsheet = objXL.Worksheets("Sheet1") 'Module Code (from modAPIFunctions): Public Declare Sub MilliSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) That code has worked reliably for me in A97 through A2K3. *Note that the MilliSleep API call was from an example in this NG. *The DoEvents might not be necessary. James A. Fortune CDMAPos... (AT) FortuneJames (DOT) com Thanks for the reply James. I can open an existing file, but can't seem to just open Excel without referencing an existing file. It's not critical, but I just wanted to provide the Office links on one of my switchboards (no data involved). It works fine for Word, but not Excel. Bob Darlington Brisbane |
#6
| |||
| |||
|
|
-- "James A. Fortune" <CDMAPos... (AT) FortuneJames (DOT) com> wrote in messagenews:1a273c7f-6ffa-45df-bdf5-d4f23a0820a2 (AT) g26g2000vbz (DOT) googlegroups.com... On Dec 18, 10:13 pm, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane Here's some code I use to open an Excel "Template" that contains all the formatting, etc. that I want: Set objXL = CreateObject("Excel.Application") Set wbk = objXL.Workbooks.Open(strTemplate) wbk.SaveAs strFQP DoEvents 'Give the OS 1.5 seconds to save the copy Call MilliSleep(1500) objXL.Visible = True Set wsheet = objXL.Worksheets("Sheet1") 'Module Code (from modAPIFunctions): Public Declare Sub MilliSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) That code has worked reliably for me in A97 through A2K3. Note that the MilliSleep API call was from an example in this NG. The DoEvents might not be necessary. James A. Fortune CDMAPos... (AT) FortuneJames (DOT) com Thanks for the reply James. I can open an existing file, but can't seem to just open Excel without referencing an existing file. It's not critical, but I just wanted to provide the Office links on one of my switchboards (no data involved). It works fine for Word, but not Excel. Bob Darlington Brisbane |
#7
| |||
| |||
|
|
-- "James A. Fortune" <CDMAPos... (AT) FortuneJames (DOT) com> wrote in messagenews:1a273c7f-6ffa-45df-bdf5-d4f23a0820a2 (AT) g26g2000vbz (DOT) googlegroups.com... On Dec 18, 10:13 pm, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane Here's some code I use to open an Excel "Template" that contains all the formatting, etc. that I want: Set objXL = CreateObject("Excel.Application") Set wbk = objXL.Workbooks.Open(strTemplate) wbk.SaveAs strFQP DoEvents 'Give the OS 1.5 seconds to save the copy Call MilliSleep(1500) objXL.Visible = True Set wsheet = objXL.Worksheets("Sheet1") 'Module Code (from modAPIFunctions): Public Declare Sub MilliSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) That code has worked reliably for me in A97 through A2K3. Note that the MilliSleep API call was from an example in this NG. The DoEvents might not be necessary. James A. Fortune CDMAPos... (AT) FortuneJames (DOT) com Thanks for the reply James. I can open an existing file, but can't seem to just open Excel without referencing an existing file. It's not critical, but I just wanted to provide the Office links on one of my switchboards (no data involved). It works fine for Word, but not Excel. Bob Darlington Brisbane |
#8
| |||
| |||
|
|
"James A. Fortune" <CDMAPoster (AT) FortuneJames (DOT) com> wrote in message news:1de8ce2d-3ace-45ba-a9c4-15e65ff69222 (AT) v17g2000yqv (DOT) googlegroups.com... On Dec 21, 1:52 am, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: -- "James A. Fortune" <CDMAPos... (AT) FortuneJames (DOT) com> wrote in messagenews:1a273c7f-6ffa-45df-bdf5-d4f23a0820a2 (AT) g26g2000vbz (DOT) googlegroups.com... On Dec 18, 10:13 pm, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane Here's some code I use to open an Excel "Template" that contains all the formatting, etc. that I want: Set objXL = CreateObject("Excel.Application") Set wbk = objXL.Workbooks.Open(strTemplate) wbk.SaveAs strFQP DoEvents 'Give the OS 1.5 seconds to save the copy Call MilliSleep(1500) objXL.Visible = True Set wsheet = objXL.Worksheets("Sheet1") 'Module Code (from modAPIFunctions): Public Declare Sub MilliSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) That code has worked reliably for me in A97 through A2K3. Note that the MilliSleep API call was from an example in this NG. The DoEvents might not be necessary. James A. Fortune CDMAPos... (AT) FortuneJames (DOT) com Thanks for the reply James. I can open an existing file, but can't seem to just open Excel without referencing an existing file. It's not critical, but I just wanted to provide the Office links on one of my switchboards (no data involved). It works fine for Word, but not Excel. Bob Darlington Brisbane If you're opening Excel by itself, you don't need to try to find an open instance. Just use CreateObject without trying to GetObject. That should avoid the error trap which might be causing the problem. James A. Fortune CDMAPoster (AT) FortuneJames (DOT) com -------------- Bob, I recently created a form with a command button to open a specific Excel Workbook to a specific worksheet, and leave the worksheet "on top" with the focus. The problem was, sometimes the worksheet would open and remain visible, sometimes not. I eventually discovered that sometimes I had a "phantom" copy of Excel running (I think I got that solved by being meticulous about explicitly "SET"ing all the objects and explicitly setting them all to nothing after I was through) -- that stray copy if Excel is listed on the Process tab of Task Manager. Then -- sometimes Excel would receive the focus (which I wanted) and sometimes not. That issue I never have completely resolved .. in my case, if Excel opens but does not receive the focus there is a tab in the windows task bar which will give Excel focus if I click on it. The code I use is quite similar to what you posted; here's what I use to try and give the focus to Excel: With xlApp If .WindowState = xlMinimized Then .WindowState = xlMaximized End If .Interactive = True .UserControl = True .Visible = True End With DoEvents Set xlSheet = Nothing Set xlBook = Nothing Set xlApp = Nothing End Sub -- Clif McIrvin (clare reads his mail with moe, nomail feeds the bit bucket :-) |
#9
| |||
| |||
|
|
I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane |
#10
| |||
| |||
|
|
Thanks Clif, that worked fine. I just needed the line 'UserControl = True'. -- Bob Darlington Brisbane "Clif McIrvin" <clare.nomail (AT) gmail (DOT) com> wrote in message news:ier5f5$t4p$1 (AT) news (DOT) eternal-september.org... "James A. Fortune" <CDMAPoster (AT) FortuneJames (DOT) com> wrote in message news:1de8ce2d-3ace-45ba-a9c4-15e65ff69222 (AT) v17g2000yqv (DOT) googlegroups.com... On Dec 21, 1:52 am, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: -- "James A. Fortune" <CDMAPos... (AT) FortuneJames (DOT) com> wrote in messagenews:1a273c7f-6ffa-45df-bdf5-d4f23a0820a2 (AT) g26g2000vbz (DOT) googlegroups.com... On Dec 18, 10:13 pm, "Bob Darlington" <b... (AT) notheredpcman (DOT) com.au wrote: I want to provide a button to permit users to open a copy of Word or Excel from within my application. I'm using: Function OpenOfficeApp(vApp As Byte) Dim obj As Object Dim strApp As String If vApp = 1 Then strApp = "Excel" Else strApp = "Word" On Error Resume Next Set obj = GetObject(, strApp & ".Application") If Err <> 0 Then Set obj = CreateObject(strApp & ".Application") On Error GoTo ErrorOfficeApp obj.Visible = True obj.WindowState = 1 '..........etc It works OK for Word but not for Excel. No error generated (error code removed from this post), the screen flashes but nothing happens. -- Bob Darlington Brisbane Here's some code I use to open an Excel "Template" that contains all the formatting, etc. that I want: Set objXL = CreateObject("Excel.Application") Set wbk = objXL.Workbooks.Open(strTemplate) wbk.SaveAs strFQP DoEvents 'Give the OS 1.5 seconds to save the copy Call MilliSleep(1500) objXL.Visible = True Set wsheet = objXL.Worksheets("Sheet1") 'Module Code (from modAPIFunctions): Public Declare Sub MilliSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) That code has worked reliably for me in A97 through A2K3. Note that the MilliSleep API call was from an example in this NG. The DoEvents might not be necessary. James A. Fortune CDMAPos... (AT) FortuneJames (DOT) com Thanks for the reply James. I can open an existing file, but can't seem to just open Excel without referencing an existing file. It's not critical, but I just wanted to provide the Office links on one of my switchboards (no data involved). It works fine for Word, but not Excel. Bob Darlington Brisbane If you're opening Excel by itself, you don't need to try to find an open instance. Just use CreateObject without trying to GetObject. That should avoid the error trap which might be causing the problem. James A. Fortune CDMAPoster (AT) FortuneJames (DOT) com -------------- Bob, I recently created a form with a command button to open a specific Excel Workbook to a specific worksheet, and leave the worksheet "on top" with the focus. The problem was, sometimes the worksheet would open and remain visible, sometimes not. I eventually discovered that sometimes I had a "phantom" copy of Excel running (I think I got that solved by being meticulous about explicitly "SET"ing all the objects and explicitly setting them all to nothing after I was through) -- that stray copy if Excel is listed on the Process tab of Task Manager. Then -- sometimes Excel would receive the focus (which I wanted) and sometimes not. That issue I never have completely resolved .. in my case, if Excel opens but does not receive the focus there is a tab in the windows task bar which will give Excel focus if I click on it. The code I use is quite similar to what you posted; here's what I use to try and give the focus to Excel: With xlApp If .WindowState = xlMinimized Then .WindowState = xlMaximized End If .Interactive = True .UserControl = True .Visible = True End With DoEvents Set xlSheet = Nothing Set xlBook = Nothing Set xlApp = Nothing End Sub -- Clif McIrvin (clare reads his mail with moe, nomail feeds the bit bucket :-) |
![]() |
| Thread Tools | |
| Display Modes | |
| |