Excel Crashes while saving embedded file thru VBA

megahurtz

New Member
Joined
Aug 16, 2011
Messages
17
Hi All,

I have a code that opens an embedded excel thru VBA, saves it on a user-specified location, closes the embedded file. Then the saved file will be opened and edited,
The problem that i'm facing is dat when i try to save the embedded sheet, excel crashes with no specified error. It simply crashes. I've no idea what to do. Please help....


My code is as shown below:

Code:
Set XlWbk = ThisWorkbook

Set oEmbFile = XlWbk.Sheets("Release Note Template").OLEObjects("Release Note Template")
oEmbFile.Verb Verb:=xlPrimary
Set XlRN = oEmbFile.Object

re_path2:
saveaspath = Application.GetSaveAsFilename(InitialFileName:=home, Title:="Save the Release Note as...", _
                    FileFilter:="Excel 2007 Files (*.xlsx), *.xlsx, Excel 97-2003 Files (*.xls), *.xls")
'Application.StatusBar = "Saving the Release Note..."
a = MsgBox("Save the Release Note on path " & saveaspath & "?", vbQuestion + vbYesNo)
If a = vbNo Then GoTo re_path2
'XlRN.SaveCopyAs saveaspath
XlRN.Activate
XlRN.SaveAs filename:=saveaspath, ReadOnlyRecommended:=False, CreateBackup:=False ', FileFormat:=xlNormal
XlRN.Close
Set oEmbFile = Nothing
Set XlRN = Nothing

Set XlRN = oExcel.Workbooks.Open(saveaspath)

XlWbk.Activate
wsRNT.Activate
The Excel crashes at point
Code:
XlRN.SaveCopyAs saveaspath
or
Code:
XlRN.SaveAs filename:=saveaspath...
Please guide. Thanks in advance... :)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
The Object Property of the OleObject Class doesn't have a SaveAs Method.
You will need a workaround in order to save an embeeded object to disk maybe by copying it to the clipboard and then to disk.
 
Upvote 0
Thanks Jaafar,

The workaround i implemented was :

Code:
XlRN.Activate
Activesheet.SaveCopyAs saveaspath

It worked!
 
Upvote 0
Thanks Jaafar,

The workaround i implemented was :

Code:
XlRN.Activate
Activesheet.SaveCopyAs saveaspath

It worked!

Hmm

Maybe I do something wrong, but if I use this line of code in a saved one-sheet simple test file, it throws an error:

Code:
ActiveSheet.SaveCopyAs "C:\onesheet.xlsm"

Am I missing something here? SaveCopyAs applies to workbooks, no?

Error: object doesn't support this object or property.
 
Upvote 0
Correct me anyone but I believe the Worksheet.SveAs was first introduced in Excel2007. Are you using excel 2003 or earlier ?

The one thing that I don't understand is that Worksheet.SaveAs saves the entire workbook and not the target worksheet as one would expect .
 
Upvote 0
My apologies, but the actual workaround i'm using is

Code:
ActiveWorkbook.savesas.....

It was a typo saying

Code:
Activesheet.saveas...
 
Upvote 0
My apologies, but the actual workaround i'm using is

Code:
ActiveWorkbook.savesas.....

It was a typo saying

Code:
Activesheet.saveas...

And then, also,

Rich (BB code):
ActiveWorkbook.SaveCopyAs saveaspath

If yes, then I'm ok. And I don't know why Jaafar could get the other one to work. Maybe someone else could confirm if the version with a sheet also works.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top