Mark01
asked on
Access VBA Object variable Error
I am trying to run the code shown below in Access, but I get an “Object variable or With block not set” error. Please help me resolve the error.
Code:
Dim myApp As Object
myApp = CreateObject("InDesign.App lication.C S6")
Dim myFileSystemObject As Object
myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
Dim myFile As String
myFile = myFileSystemObject.GetFile ("C:\Temp\ 1.jsx")
I also tried, but I get the same error:
Dim myFile As Long
The following code runs without any errors in VB.Net:
Dim myApp As Object
myApp = CreateObject("InDesign.App lication.C S6")
Dim myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
Dim myFile = myFileSystemObject.GetFile ("C:\Temp\ 1.jsx")
myApp.DoScript(myFile, InDesign.idScriptLanguage. idJavascri pt)
myApp = Nothing
Code:
Dim myApp As Object
myApp = CreateObject("InDesign.App
Dim myFileSystemObject As Object
myFileSystemObject = CreateObject("Scripting.Fi
Dim myFile As String
myFile = myFileSystemObject.GetFile
I also tried, but I get the same error:
Dim myFile As Long
The following code runs without any errors in VB.Net:
Dim myApp As Object
myApp = CreateObject("InDesign.App
Dim myFileSystemObject = CreateObject("Scripting.Fi
Dim myFile = myFileSystemObject.GetFile
myApp.DoScript(myFile, InDesign.idScriptLanguage.
myApp = Nothing
This:
Dim myFile As String
myFile = myFileSystemObject.GetFile ("C:\Temp\ 1.jsx")
is incorrect. GetFile returns a file object, not a string.
Jim.
Dim myFile As String
myFile = myFileSystemObject.GetFile
is incorrect. GetFile returns a file object, not a string.
Jim.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Probably the error is before
Dim myApp As Object
set myApp = CreateObject("InDesign.Application.CS6")
Dim myFileSystemObject As Object
set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
'Dim myFile As String ' This will get the path of the file
Dim myFile As Object
set myFile = myFileSystemObject.GetFile("C:\Temp\1.jsx")
ASKER
The last line is highlighted in red (syntax error) with the following:
Dim myApp As Object
myApp = CreateObject("InDesign.App lication.C S6")
Dim myFileSystemObject As Object
myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
myApp.DoScript(myFile, InDesign.idScriptLanguage. idJavascri pt)
and
Dim myApp As Object
myApp = CreateObject("InDesign.App lication")
Dim myFileSystemObject As Object
myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
myApp.DoScript(myFile, InDesign.idScriptLanguage. idJavascri pt)
Dim myApp As Object
myApp = CreateObject("InDesign.App
Dim myFileSystemObject As Object
myFileSystemObject = CreateObject("Scripting.Fi
myApp.DoScript(myFile, InDesign.idScriptLanguage.
and
Dim myApp As Object
myApp = CreateObject("InDesign.App
Dim myFileSystemObject As Object
myFileSystemObject = CreateObject("Scripting.Fi
myApp.DoScript(myFile, InDesign.idScriptLanguage.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get a runtime error “‘Object doesn’t support this property or method” with the following:
Dim myApp As Object
set myApp = CreateObject("InDesign.App lication.C S6")
Dim myFileSystemObject As Object
set myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
'Dim myFile As String ' This will get the path of the file
Dim myFile As Object
set myFile = myFileSystemObject.GetFile ("C:\Temp\ 1.jsx")
myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
Dim myApp As Object
set myApp = CreateObject("InDesign.App
Dim myFileSystemObject As Object
set myFileSystemObject = CreateObject("Scripting.Fi
'Dim myFile As String ' This will get the path of the file
Dim myFile As Object
set myFile = myFileSystemObject.GetFile
myFileSystemObject = CreateObject("Scripting.Fi
You have already created last object
Which line of code is causing the error?
ASKER
I get a syntax error on the last line (highlighted in red) with the following:
Dim myApp As Object
Dim myFileSystemObject As Object
Set myApp = CreateObject("InDesign.App lication")
Set myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
myApp.DoScript (myFile, InDesign.idScriptLanguage. idJavascri pt)
Dim myApp As Object
Dim myFileSystemObject As Object
Set myApp = CreateObject("InDesign.App
Set myFileSystemObject = CreateObject("Scripting.Fi
myApp.DoScript (myFile, InDesign.idScriptLanguage.
What is it that your trying to accomplish with this code?
Jim.
Jim.
ASKER
@Jim Dettman: I am trying to run the 1.jsx script.
ASKER
With the following, there are no errors and InDesign starts, but the "1.jsx"script will not run.
Dim myApp As Object
Dim myFileSystemObject As Object
Set myApp = CreateObject("InDesign.App lication.C S6")
Set myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
Dim myFile As Object
Set myFile = myFileSystemObject.GetFile ("C:\Temp\ 1.jsx")
Set myApp = Nothing
Dim myApp As Object
Dim myFileSystemObject As Object
Set myApp = CreateObject("InDesign.App
Set myFileSystemObject = CreateObject("Scripting.Fi
Dim myFile As Object
Set myFile = myFileSystemObject.GetFile
Set myApp = Nothing
Dim myApp As Object
Dim myFileSystemObject As Object
Dim myFile As Object
Dim myFilePath As String
Dim myFileText as String
' Start application
Set myApp = CreateObject("InDesign.App lication.C S6")
' Need to get contents of script file.
Set myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
myFilePath = "C:\Temp\1.jsx"
Set myFile = myFileSystemObject.OpenTex tFile(myFi lePath, ForReading)
myFileText = myFile.ReadAll
myFile.Close
Set myFile = Nothing
myApp.DoScript (myFileText , InDesign.idScriptLanguage. idJavascri pt)
Set myFileSystemObject = nothing
Set myApp = nothing
Should be close. You want to read the file contents, then execute. DoScript's first parameter is a string containing the script.
Jim.
Dim myFileSystemObject As Object
Dim myFile As Object
Dim myFilePath As String
Dim myFileText as String
' Start application
Set myApp = CreateObject("InDesign.App
' Need to get contents of script file.
Set myFileSystemObject = CreateObject("Scripting.Fi
myFilePath = "C:\Temp\1.jsx"
Set myFile = myFileSystemObject.OpenTex
myFileText = myFile.ReadAll
myFile.Close
Set myFile = Nothing
myApp.DoScript (myFileText , InDesign.idScriptLanguage.
Set myFileSystemObject = nothing
Set myApp = nothing
Should be close. You want to read the file contents, then execute. DoScript's first parameter is a string containing the script.
Jim.
ASKER
With the following, there are no errors and InDesign starts, but the "1.jsx"script will not run.
There is a syntax error on:
myApp.DoScript (myFile, InDesign.idScriptLanguage. idJavascri pt)
Code:
Dim myApp As Object
Dim myFileSystemObject As Object
Set myApp = CreateObject("InDesign.App lication.C S6")
Set myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
Dim myFile As Object
Set myFile = myFileSystemObject.GetFile ("C:\Temp\ 1.jsx")
myApp.DoScript (myFile, InDesign.idScriptLanguage. idJavascri pt)
Set myApp = Nothing
There is a syntax error on:
myApp.DoScript (myFile, InDesign.idScriptLanguage.
Code:
Dim myApp As Object
Dim myFileSystemObject As Object
Set myApp = CreateObject("InDesign.App
Set myFileSystemObject = CreateObject("Scripting.Fi
Dim myFile As Object
Set myFile = myFileSystemObject.GetFile
myApp.DoScript (myFile, InDesign.idScriptLanguage.
Set myApp = Nothing
ASKER
My previous post erroneously stated that there are no errors and InDesign starts.
With the following there is a syntax error on:
myApp.DoScript (myFile, InDesign.idScriptLanguage. idJavascri pt)
Code:
Dim myApp As Object
Dim myFileSystemObject As Object
Dim myFile As Object
Dim myFilePath As String
Dim myFileText As String
' Start application
Set myApp = CreateObject("InDesign.App lication.C S6")
' Need to get contents of script file.
Set myFileSystemObject = CreateObject("Scripting.Fi leSystemOb ject")
myFilePath = "C:\Temp\1.jsx"
Set myFile = myFileSystemObject.OpenTex tFile(myFi lePath, ForReading)
myFileText = myFile.ReadAll
myFile.Close
Set myFile = Nothing
myApp.DoScript (myFileText , InDesign.idScriptLanguage. idJavascri pt)
Set myFileSystemObject = Nothing
Set myApp = Nothing
With the following there is a syntax error on:
myApp.DoScript (myFile, InDesign.idScriptLanguage.
Code:
Dim myApp As Object
Dim myFileSystemObject As Object
Dim myFile As Object
Dim myFilePath As String
Dim myFileText As String
' Start application
Set myApp = CreateObject("InDesign.App
' Need to get contents of script file.
Set myFileSystemObject = CreateObject("Scripting.Fi
myFilePath = "C:\Temp\1.jsx"
Set myFile = myFileSystemObject.OpenTex
myFileText = myFile.ReadAll
myFile.Close
Set myFile = Nothing
myApp.DoScript (myFileText , InDesign.idScriptLanguage.
Set myFileSystemObject = Nothing
Set myApp = Nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<<I don't see the need for the file system object, the DoScript method is expecting a string as the first parm referencing the JSX file to run.>>
Referencing the file, or the actual script as a string? I thought it was the later.
Jim.
Referencing the file, or the actual script as a string? I thought it was the later.
Jim.
Jim, seems to want the file path, not content...
»bp
»bp
ASKER
Bill solved the problem. Thank you, Bill, John, Jim, and Norie.
Glad that helped.
»bp
»bp
Open in new window
or you should change it toOpen in new window