Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default opening file by a macro (in Excel2007)


Hi all,

I have a macro that creates a file with a pivot-table in it, and saves it
with a generated name based on the value of a specific cell.
The filename is stored in a global variable.
Next I run another macro that should open the file, but this causes an error
Run-time error 1004 " Method 'Open' of object 'Workbooks failed.

Below the relevant statements.

Public myName As Integer

Macro (1)
Range("F3").Select
myName = ActiveCell.Value

ActiveWorkbook.SaveAs Filename:="C:\Temp\" & myName & ".xlsm"

for opening the file this is the statement in a separate
Macro(2)
ChDir "C:\Temp"
Workbooks.Open Filename:="C:\Temp\" & myName

What also troubles me is that in Explorer I get another error message on
trying to open the file: "Excel cannot open the file [NAME] because the file
format or file extension is not valid. Verify that the file has not been
corrupted and that the file extension matches the format of the file".

Can anybody tell me what goes wrong?

Regards,

Willem



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default opening file by a macro (in Excel2007)


try these changes

from
ChDir "C:\Temp"
Workbooks.Open Filename:="C:\Temp\" & myName
to
Chdrive "C"
Folder = "C:\Temp\"
FName = dir(Folder & myName & ".xls*"
if FName = "" then
msgbox("Cannot find file : " & myName)
else
Workbooks.Open Filename:=Folder & FName
end if

"Willem" wrote:

Hi all,

I have a macro that creates a file with a pivot-table in it, and saves it
with a generated name based on the value of a specific cell.
The filename is stored in a global variable.
Next I run another macro that should open the file, but this causes an error
Run-time error 1004 " Method 'Open' of object 'Workbooks failed.

Below the relevant statements.

Public myName As Integer

Macro (1)
Range("F3").Select
myName = ActiveCell.Value

ActiveWorkbook.SaveAs Filename:="C:\Temp\" & myName & ".xlsm"

for opening the file this is the statement in a separate
Macro(2)
ChDir "C:\Temp"
Workbooks.Open Filename:="C:\Temp\" & myName

What also troubles me is that in Explorer I get another error message on
trying to open the file: "Excel cannot open the file [NAME] because the file
format or file extension is not valid. Verify that the file has not been
corrupted and that the file extension matches the format of the file".

Can anybody tell me what goes wrong?

Regards,

Willem



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
delay in opening an excel file in excel2007 from the explorer wind CuriousAnt New Users to Excel 0 January 16th 10 06:12 PM
Pivot table range selection changes when opening 2003 xls in Excel2007 Saqib Ali Excel Discussion (Misc queries) 4 July 2nd 08 11:47 AM
Pivot table range selection changes when opening 2003 xls in Excel2007 Saqib Ali Excel Worksheet Functions 4 July 2nd 08 11:47 AM
Pivot table range selection changes when opening 2003 xls in Excel2007 Saqib Ali Charts and Charting in Excel 4 July 2nd 08 11:47 AM
VBA project opening problem in Excel2007 Maz Excel Discussion (Misc queries) 0 October 17th 07 12:39 AM


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

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"