Open & run a workbook macro.

  • Thread starter Thread starter Julian Milano
  • Start date Start date
J

Julian Milano

I have a source wb, with the following code in a code module:

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Workbooks.Open vPath & "\" & vWBOpenDataFileName
Debug.Print Application.Run("[" & vWBOpenDataFileName &
"]!OpenDJSalesData")
Stop
End Sub

It should open another wb called "DJ Sales Data Import macro for
Judith.xls", and run the macro "OpenDJSalesData". But I get the error
"Runtime error 1004: A document with the name "DJ Sales Data Import macro
for Judith.xls" is already open. You can not open two documents with the
same name, even if they are in different folders........". This error
occurrs on the Debug.Print line.

Why is this happening?

WinXP SP1, XL2002.
 
Julian,

Try this slightly amended version

Change

Debug.Print Application.Run("[" & vWBOpenDataFileName
&"]!OpenDJSalesData")

to

Debug.Print Application.Run(vWBOpenDataFileName & "!OpenDJSalesData")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Try this ( you might need to ensure the OpenDJSalesData macro is define
as Public ) -

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

Dim wbkSalesDataMacro As Workbook

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Set wbkSalesDataMacro = Workbooks.Open(vPath & "\"
vWBOpenDataFileName)
Debug.Print wbkSalesDataMacro.OpenDJSalesData
Stop
End Su
 
Bob,

I got the error "Error 1004: The macro 'DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData' can not be found."

Note that the macro I am trying to run is in a code module called "mMain".

--

Julian Milano


Bob Phillips said:
Julian,

Try this slightly amended version

Change

Debug.Print Application.Run("[" & vWBOpenDataFileName
&"]!OpenDJSalesData")

to

Debug.Print Application.Run(vWBOpenDataFileName & "!OpenDJSalesData")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
I have a source wb, with the following code in a code module:

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Workbooks.Open vPath & "\" & vWBOpenDataFileName
Debug.Print Application.Run("[" & vWBOpenDataFileName &
"]!OpenDJSalesData")
Stop
End Sub

It should open another wb called "DJ Sales Data Import macro for
Judith.xls", and run the macro "OpenDJSalesData". But I get the error
"Runtime error 1004: A document with the name "DJ Sales Data Import macro
for Judith.xls" is already open. You can not open two documents with the
same name, even if they are in different folders........". This error
occurrs on the Debug.Print line.

Why is this happening?

WinXP SP1, XL2002.
 
Julian,

Well at least it has moved forward<vbg>.

As long as the macro exists, is not private, and is in a standard code
module, you should find it.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
Bob,

I got the error "Error 1004: The macro 'DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData' can not be found."

Note that the macro I am trying to run is in a code module called "mMain".

--

Julian Milano


Bob Phillips said:
Julian,

Try this slightly amended version

Change

Debug.Print Application.Run("[" & vWBOpenDataFileName
&"]!OpenDJSalesData")

to

Debug.Print Application.Run(vWBOpenDataFileName & "!OpenDJSalesData")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
I have a source wb, with the following code in a code module:

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Workbooks.Open vPath & "\" & vWBOpenDataFileName
Debug.Print Application.Run("[" & vWBOpenDataFileName &
"]!OpenDJSalesData")
Stop
End Sub

It should open another wb called "DJ Sales Data Import macro for
Judith.xls", and run the macro "OpenDJSalesData". But I get the error
"Runtime error 1004: A document with the name "DJ Sales Data Import macro
for Judith.xls" is already open. You can not open two documents with the
same name, even if they are in different folders........". This error
occurrs on the Debug.Print line.

Why is this happening?

WinXP SP1, XL2002.
 
Guys,

What I've found is that if I use this line:

Debug.Print Application.Run("DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData")

..... I get the macro-can't-be-found error. But if I use the following line:

Debug.Print
Application.Run("DJSalesDataImportmacroforJudith.xls!OpenDJSalesData")

.....ie. with no spaces (and with the workbook saved under the new name), it
works. So, my next question is....How do I run a macro in another workbook,
where the workbook name contains spaces??

XL2002 on WinXP SP1.


--

Julian Milano


Bob Phillips said:
Julian,

Well at least it has moved forward<vbg>.

As long as the macro exists, is not private, and is in a standard code
module, you should find it.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
Bob,

I got the error "Error 1004: The macro 'DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData' can not be found."

Note that the macro I am trying to run is in a code module called "mMain".

--

Julian Milano


Bob Phillips said:
Julian,

Try this slightly amended version

Change

Debug.Print Application.Run("[" & vWBOpenDataFileName
&"]!OpenDJSalesData")

to

Debug.Print Application.Run(vWBOpenDataFileName & "!OpenDJSalesData")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

I have a source wb, with the following code in a code module:

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Workbooks.Open vPath & "\" & vWBOpenDataFileName
Debug.Print Application.Run("[" & vWBOpenDataFileName &
"]!OpenDJSalesData")
Stop
End Sub

It should open another wb called "DJ Sales Data Import macro for
Judith.xls", and run the macro "OpenDJSalesData". But I get the error
"Runtime error 1004: A document with the name "DJ Sales Data Import macro
for Judith.xls" is already open. You can not open two documents with the
same name, even if they are in different folders........". This error
occurrs on the Debug.Print line.

Why is this happening?

WinXP SP1, XL2002.
 
Julian,

Debug.Print Application.Run("'DJ Sales Data Import macro for
Judith.xls'!OpenDJSalesData")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
Guys,

What I've found is that if I use this line:

Debug.Print Application.Run("DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData")

.... I get the macro-can't-be-found error. But if I use the following line:

Debug.Print
Application.Run("DJSalesDataImportmacroforJudith.xls!OpenDJSalesData")

....ie. with no spaces (and with the workbook saved under the new name), it
works. So, my next question is....How do I run a macro in another workbook,
where the workbook name contains spaces??

XL2002 on WinXP SP1.


--

Julian Milano


Bob Phillips said:
Julian,

Well at least it has moved forward<vbg>.

As long as the macro exists, is not private, and is in a standard code
module, you should find it.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
Bob,

I got the error "Error 1004: The macro 'DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData' can not be found."

Note that the macro I am trying to run is in a code module called "mMain".

--

Julian Milano


Julian,

Try this slightly amended version

Change

Debug.Print Application.Run("[" & vWBOpenDataFileName
&"]!OpenDJSalesData")

to

Debug.Print Application.Run(vWBOpenDataFileName & "!OpenDJSalesData")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

I have a source wb, with the following code in a code module:

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Workbooks.Open vPath & "\" & vWBOpenDataFileName
Debug.Print Application.Run("[" & vWBOpenDataFileName &
"]!OpenDJSalesData")
Stop
End Sub

It should open another wb called "DJ Sales Data Import macro for
Judith.xls", and run the macro "OpenDJSalesData". But I get the error
"Runtime error 1004: A document with the name "DJ Sales Data Import
macro
for Judith.xls" is already open. You can not open two documents
with
the
same name, even if they are in different folders........". This error
occurrs on the Debug.Print line.

Why is this happening?

WinXP SP1, XL2002.
 
Bob,

LIFESAVER!!!

--

Julian Milano


Bob Phillips said:
Julian,

Debug.Print Application.Run("'DJ Sales Data Import macro for
Judith.xls'!OpenDJSalesData")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Julian Milano said:
Guys,

What I've found is that if I use this line:

Debug.Print Application.Run("DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData")

.... I get the macro-can't-be-found error. But if I use the following line:

Debug.Print
Application.Run("DJSalesDataImportmacroforJudith.xls!OpenDJSalesData")

....ie. with no spaces (and with the workbook saved under the new name), it
works. So, my next question is....How do I run a macro in another workbook,
where the workbook name contains spaces??

XL2002 on WinXP SP1.


--

Julian Milano


Bob Phillips said:
Julian,

Well at least it has moved forward<vbg>.

As long as the macro exists, is not private, and is in a standard code
module, you should find it.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Bob,

I got the error "Error 1004: The macro 'DJ Sales Data Import macro for
Judith.xls!OpenDJSalesData' can not be found."

Note that the macro I am trying to run is in a code module called "mMain".

--

Julian Milano


Julian,

Try this slightly amended version

Change

Debug.Print Application.Run("[" & vWBOpenDataFileName
&"]!OpenDJSalesData")

to

Debug.Print Application.Run(vWBOpenDataFileName &
"!OpenDJSalesData")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

I have a source wb, with the following code in a code module:

Dim vPath As String
Dim vWBOpenDataFileName As String

Sub OpenDataFile()

vPath = ActiveWorkbook.Path
vWBOpenDataFileName = "DJ Sales Data Import macro for Judith.xls"
Workbooks.Open vPath & "\" & vWBOpenDataFileName
Debug.Print Application.Run("[" & vWBOpenDataFileName &
"]!OpenDJSalesData")
Stop
End Sub

It should open another wb called "DJ Sales Data Import macro for
Judith.xls", and run the macro "OpenDJSalesData". But I get the error
"Runtime error 1004: A document with the name "DJ Sales Data Import
macro
for Judith.xls" is already open. You can not open two documents with
the
same name, even if they are in different folders........". This error
occurrs on the Debug.Print line.

Why is this happening?

WinXP SP1, XL2002.
 
Back
Top