Thread: Run Time 1004
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Run Time 1004

Thanks for the catch. I know all too well that anything with a blank needs
single quotes around it.

"Tim Zych" wrote:

That won't work. You need single quotes around the workbook name due to the
fact that it has a space in it.

This modification will work with any workbook name, no matter whether it has
spaces in it or apostrophes or not. Both are considerations when using Run.

Application.Run ("'" & Replace(myWB.Name,"'","''") & "'!Inventory")


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"Barb Reinhardt" wrote in message
...
I've tweaked it a bit. Let me know if it works

Option Explicit

Sub Test()
Dim myWB As Excel.Workbook
Dim myFilePath As String

myFilePath = "G:\Purchasing\Robert's Stuff\Inventory Studies\Inventory
Study9.xls"

On Error Resume Next
Set myWB = Workbooks.Open(Filename:=myFilePath)
On Error GoTo 0

If myWB Is Nothing Then
MsgBox ("Workbook not opened")
End
End If

Application.Run (myWB.Name & "!Inventory")

End Sub


"Rpettis31" wrote:

I have the following code that states that the macro/sub cannot be found
yet,
and I am not sure why, the workbook opens and I simply copied the path in
my
code and then added the macro call. Not sure why I am getting this
error.

Workbooks.Open Filename:= _
"G:\Purchasing\Robert's Stuff\Inventory Studies\Inventory Study9.xls"

Workbooks("Inventory Study9.xls").Activate

Application.Run ("'G:\Purchasing\Robert's Stuff\Inventory
Studies\Inventory Study9.xls'!Inventory")