Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default VBA Expected end of statement ERROR

I created this macro in Microsoft Visual Basic wihin excel and
exported it as a VBS file. The macro runs fine within excel but if I
run it from my desktop I get an end of statement error.

Any Ideas?

Paul

Dim udpatedate As String
Dim myFile As String


Sub OpenBookTest()

Dim myPath As String
Dim myFile As String


myPath = "W:\YIELDMGT\Paul Lambson\SAS"
myFile = "ThanksChart.xls"

Set wbk = Workbooks.Open(Filename:=myPath & "\" & myFile, _
Password:="turkey", WriteResPassword:="turkey", UpdateLinks:=True)
ActiveWorkbook.RefreshAll
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA Expected end of statement ERROR

On Nov 18, 10:42*am, Paul Lambson wrote:
I created this macro in Microsoft Visual Basic wihin excel and
exported it as a VBS file. The macro runs fine within excel but if I
run it from my desktop I get an end of statement error.

Any Ideas?

Paul

Dim udpatedate As String
Dim myFile As String

Sub OpenBookTest()

Dim myPath As String
Dim myFile As String

myPath = "W:\YIELDMGT\Paul Lambson\SAS"
myFile = "ThanksChart.xls"

Set wbk = Workbooks.Open(Filename:=myPath & "\" & myFile, _
Password:="turkey", WriteResPassword:="turkey", UpdateLinks:=True)
ActiveWorkbook.RefreshAll
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub


So, you don't have access to the excel object natively from VBS, but
you can access it by creating the excel object. I found some code on
creating an object, but I can't say I've ever done it.

Here's the example.
Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.WorkBooks.Open("C:\Scripts\test1.xls")
Set objWS = objXL.ActiveWorkBook.WorkSheets("test1")

Dim CellArray()
ACount = 0
For i = 300 To 350
If objXL.Cells(i, 9).Value = "" Then
CellValue = "Empty"
Else
CellValue = objXL.Cells(i, 9).Value
End If

ReDim preserve CellArray(ACount)
CellArray(ACount) = CellValue
ACount = ACount + 1
Next
objWB.Close
objXL.Quit


from this website http://www.visualbasicscript.com/m_32435/tm.htm

yours,

Sam
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA Expected end of statement ERROR



so with your code


Dim udpatedate As String
Dim myFile As String

Sub OpenBookTest()

Dim myPath As String
Dim myFile As String

myPath = "W:\YIELDMGT\Paul Lambson\SAS"
myFile = "ThanksChart.xls"

Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.Workbooks.Open(Filename:=myPath & "\" & myFile, _
Password:="turkey", WriteResPassword:="turkey", UpdateLinks:=True)

objWB.RefreshAll
objWB.Save
objWB.Close
objWB.Quit
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA Expected end of statement ERROR

In VBScript, everything is a Variant data type, so you can't use "As
whatever" when declaring variables. Use Dim and nothing else. E.g.

Dim S ' OK
Dim S As String 'Illegal

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Tue, 18 Nov 2008 09:42:08 -0800 (PST), Paul Lambson
wrote:

I created this macro in Microsoft Visual Basic wihin excel and
exported it as a VBS file. The macro runs fine within excel but if I
run it from my desktop I get an end of statement error.

Any Ideas?

Paul

Dim udpatedate As String
Dim myFile As String


Sub OpenBookTest()

Dim myPath As String
Dim myFile As String


myPath = "W:\YIELDMGT\Paul Lambson\SAS"
myFile = "ThanksChart.xls"

Set wbk = Workbooks.Open(Filename:=myPath & "\" & myFile, _
Password:="turkey", WriteResPassword:="turkey", UpdateLinks:=True)
ActiveWorkbook.RefreshAll
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expected end of statement error Patrick C. Simonds Excel Programming 1 August 14th 08 08:28 PM
Overcome "expected end of statement error" burl_rfc Excel Programming 2 February 20th 07 03:49 PM
Micrsoft Visual Basic Compile error: Expected: end of statement IJ Excel Discussion (Misc queries) 5 October 23rd 06 12:08 AM
Formula expected end of statement error, typing formula into cell as part of VBA macro [email protected] Excel Programming 1 July 20th 06 07:58 PM
Expected end of Statement FIRSTROUNDKO via OfficeKB.com Excel Worksheet Functions 2 April 11th 06 11:59 AM


All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"