Code Stops Prematurely

G

Guest

I'm running code that saves a workbook abd then it should build a string and
then save another workbook. The code stops after the first workbook is saved
and the code never completes. Any suggestions on how to correct when using
the following:

ActiveWorkbook.SaveAs Filename:=XLSFILE, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

'return to the XLS file and close it
Windows(temp_xls_file).Activate
Workbooks(temp_xls_file).Close SaveChanges:=False

temp_file = "Hg Injection - " & the_sample_no & ".CSV"
CSVFILE = "V:\" + temp_file

'save a copy of the CSV file so that the XLS file will be imported
Windows("Hg Injection Exporter.xls").Activate
ActiveWorkbook.SaveAs Filename:=CSVFILE, FileFormat:= _
xlCSVMSDOS, CreateBackup:=False
 
H

Henry

Halray,

If your code is in temp_xls_file then your problem is:

When you SaveAs you change the name of the active workbook so it now becomes
XLSFILE_

Windows(temp_xls_file).Activate will fail as there is no longer a file of
this name open.

Henry
 
G

Guest

Thanks for the sugesstions - I found a work around (not sure if it's the best?)

I disabled alerts with:
Application.DisplayAlerts = False
then I saved all files as needed and quit Excel with:
Application.Quit

Thanks again for your time and efforts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Simplify save code 11
Hiding an Excel file using VBA 1
Save with ref. to cell A1 2
Code Stops Executing 1
Saving a workbook to an iKnow portal 2
File SaveAs 1
Create CSV 3
Conversion from text to excel 2

Top