ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open & run a workbook macro. (https://www.excelbanter.com/excel-programming/289371-open-run-workbook-macro.html)

Julian Milano[_2_]

Open & run a workbook macro.
 
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 Milano




Bob Phillips[_6_]

Open & run a workbook macro.
 
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" wrote in message
...
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 Milano






humejap

Open & run a workbook macro.
 
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

--
Message posted from http://www.ExcelForum.com


Julian Milano[_2_]

Open & run a workbook macro.
 
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" wrote in message
...
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" wrote in message
...
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 Milano








Bob Phillips[_6_]

Open & run a workbook macro.
 
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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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 Milano










Julian Milano[_2_]

Open & run a workbook macro.
 
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.x ls!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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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 Milano












Bob Phillips[_6_]

Open & run a workbook macro.
 
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" wrote in message
...
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.x ls!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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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 Milano














Julian Milano[_2_]

Open & run a workbook macro.
 
Bob,

LIFESAVER!!!

--

Julian Milano


"Bob Phillips" wrote in message
...
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" wrote in message
...
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.x ls!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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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 Milano

















All times are GMT +1. The time now is 09:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com