 |
| View previous topic :: View next topic |
| Author |
Message |
pwdrvr Newbie
Joined: 08 Aug 2005 Posts: 13
|
Posted: Aug 11th, 2005 07:27 AM Post subject: working with worksheets |
|
|
| i have no problem writing a code that opens excel now i can't figure out how to open a certain workbook or worksheet in a workbook please help |
|
| Back to top |
|
dougthomas Moderator
Joined: 27 Jul 2005 Posts: 271 Location: Essex, UK
|
Posted: Aug 12th, 2005 05:37 AM Post subject: |
|
|
Hi,
Here's the bit you know:
| Code: |
On Error Resume Next
Set appExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set appExcel = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0
|
Here's the bit you are asking about:
| Code: |
Dim wbWorkBook as Excel.Workbook
Dim shtSheet As Excel.Worksheet
Dim strWorkbook as string
Dim strSheet as string
strWorkbook ="fully qualified path to the Workbook"
strSheet = "sheet name of the sheet to open"
Set wbWorkBook = appExcel.Workbooks.Open(strWorkBook)
Set shtSheet = wbWorkBook.Sheets(strSheet)
|
When you've finished processing:
| Code: |
wbWorkBook.Save
wbWorkBook.Close
set shtSheet = Nothing
set wbWorkBook = Nothing
|
Good luck,
Regards
Doug |
|
| Back to top |
|
pwdrvr Newbie
Joined: 08 Aug 2005 Posts: 13
|
Posted: Aug 12th, 2005 09:12 AM Post subject: |
|
|
ok we know what i'm trying to do and everything i try isn't working
so maybe if i give you what i've got so far you can tell me where i went wrong
Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Sub Excel_Click()
Rem this will minimize all windows first
Call keybd_event(&H5B, 0, 0, 0)
Call keybd_event(&H4D, 0, 0, 0)
Call keybd_event(&H5B, 0, &H2, 0)
Rem this will open excel
Call Shell("C:\Program Files\Microsoft Office\OFFICE11\excel.exe", vbMaximizedFocus)
Dim wbWorkBook As Excel.Workbook
Dim shtSheet As Excel.Worksheet
Dim strWorkbook As String
Dim strSheet As String
strWorkbook = "C:\Documents and Settings\Josh\My Documents\Mrp Updates\Mrp update.xls"
strSheet = "PO"
Set wbWorkBook = appExcel.Workbooks.Open(strWorkbook)
Set shtSheet = wbWorkBook.Sheets(strSheet)
End Sub
where is the error?¿ |
|
| Back to top |
|
dougthomas Moderator
Joined: 27 Jul 2005 Posts: 271 Location: Essex, UK
|
Posted: Aug 12th, 2005 12:06 PM Post subject: |
|
|
Hi again,
I can't see anything wrong with the code. Have you added a reference to the Excel Object Library to your Project ? (From the Project, References menu for the project)
Are you getting some sort of error message? If so what is it?
What are you expecting to see ?
Looking at your code, just before the "End Sub" you have opened Spreadsheet PO in
C:\Documents and Settings\Josh\My Documents\Mrp Updates\Mrp update.xls
I assume you want to do something with it now that it's open.
if you just want to display it, try putting
shtSheet.Visible = xlSheetVisible
after the set ShtSheet = wbWorkBook.Sheets(strSheet) statement.
What exactly are you trying to do ?
Regards
Doug |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|