justagrunt
Technical User
- Oct 10, 2002
- 132
Hi,
Two questions.
1)When I automate excel I get the application window opening but not the worksheet, so advise please where am I going wrong? (please be kind).
Private Sub Open_Excel()
'Find and open the Excel workbook with
'the pricing for the various Selector sizes.
'The Workbook does not have to be visible.
'set up variables for working with excel.
Dim fisexcelrunning As Boolean
Dim xlapp As excel.Application 'Excel application Object
Dim xlbook As excel.Workbook 'Excel object-workbook
Dim xlsheet As excel.Sheets 'excel worksheet within the workbook
'create an Excel instance i.e set up an active instance
'use an existing instance if there is one;otherwise
'create a new instance
On Error Resume Next
Set xlapp = GetObject(, "Excel.application")
If Err.Number = 429 Then
fisexcelrunning = False
'excel isn't running: create Excel Instance
Set xlapp = CreateObject("Excel.Application")
Err.Clear
Else
fisexcelrunning = True
End If
'Open relevant workbook and page
Set xlbook = xlapp.Workbook.Open(FileName:="C:\My Documents\2WAYPRICES")
'set refernce to worksheet object
Set xlsheet = xlbook.Sheets("sheet2").Activate
xlsheet.Visible = True ‘as a check make visible.
'CHECK MESSAGE FOR PROGRESS
MsgBox "Ok To Here", vbOKOnly
End Sub
Question 2
Once I get the workbook open to the correct sheet
How do I correctly set the object variable in the following to relate to the sheet?
Case Is = 100
Call Open_Excel
With xlapp
Set rng4 = xlsheet.Range("e4:e75")
xlsheet.Range("e4").Activate
End With
'CHECK MESSAGE BOX FOR DEBUGG
MsgBox "Ok back in main. Ok to here", vbOKOnly
Price_2way
I think i've got the "With Block sorted out" as the error now relates to the object variable.
This is a continuing drama of trial and error so please be patient and forgiving.
Kind Regards
bill
Two questions.
1)When I automate excel I get the application window opening but not the worksheet, so advise please where am I going wrong? (please be kind).
Private Sub Open_Excel()
'Find and open the Excel workbook with
'the pricing for the various Selector sizes.
'The Workbook does not have to be visible.
'set up variables for working with excel.
Dim fisexcelrunning As Boolean
Dim xlapp As excel.Application 'Excel application Object
Dim xlbook As excel.Workbook 'Excel object-workbook
Dim xlsheet As excel.Sheets 'excel worksheet within the workbook
'create an Excel instance i.e set up an active instance
'use an existing instance if there is one;otherwise
'create a new instance
On Error Resume Next
Set xlapp = GetObject(, "Excel.application")
If Err.Number = 429 Then
fisexcelrunning = False
'excel isn't running: create Excel Instance
Set xlapp = CreateObject("Excel.Application")
Err.Clear
Else
fisexcelrunning = True
End If
'Open relevant workbook and page
Set xlbook = xlapp.Workbook.Open(FileName:="C:\My Documents\2WAYPRICES")
'set refernce to worksheet object
Set xlsheet = xlbook.Sheets("sheet2").Activate
xlsheet.Visible = True ‘as a check make visible.
'CHECK MESSAGE FOR PROGRESS
MsgBox "Ok To Here", vbOKOnly
End Sub
Question 2
Once I get the workbook open to the correct sheet
How do I correctly set the object variable in the following to relate to the sheet?
Case Is = 100
Call Open_Excel
With xlapp
Set rng4 = xlsheet.Range("e4:e75")
xlsheet.Range("e4").Activate
End With
'CHECK MESSAGE BOX FOR DEBUGG
MsgBox "Ok back in main. Ok to here", vbOKOnly
Price_2way
I think i've got the "With Block sorted out" as the error now relates to the object variable.
This is a continuing drama of trial and error so please be patient and forgiving.
Kind Regards
bill