VBA stops when Save As dialog box appears?

stever99

New Member
Joined
May 12, 2010
Messages
6
Hi folks,

I'm having a problem trying to automate a task in Excel because my VB formula requires a manual press of the Enter button or a click on "OK" in the Save As dialog box.

The relevant part of the code is as follows:

Code:
Application.GetSaveAsFilename( _
initialfilename:=ActiveCell.Offset(0, 1), filefilter:=sFilter)

The macro basically saves an image on the clipboard as the filename specified in the adjacent cell. This is looped so that the routine should proceed row by row:

Code:
Loop Until IsEmpty(ActiveCell.Offset(0, 1))

However, each time the function executes, the Save As dialog box appears and the macro will not proceed to the next row until I click "OK" in the Save As dialog box. I want to just save the file as the filename specified in the adjacent cell but I can't get around the manual click on "OK" to save the file. I have tried using SendKeys and simulating a left mouse click with focus applied to the "OK" button, but the problem is that the VBA function just seems to stop and wait for user input before proceeding.

Is there any way I can have the filename functionality of the SaveAs command without the manual entry in the SaveAs dialog box?

Thanks!!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
By the way, have tried using

Code:
Application.DisplayAlerts = False

But the dialog box appears anyway :(
 
Upvote 0
If you just want to SaveAs a coded filename without the dialog then use something like :-

Code:
ActiveWorkbook.SaveAs Filename:="F:\book1.xls"

(You could have recorded a macro to get this code)
 
Upvote 0
Mmm, this doesn't work because I'm not actually saving the workbook, I'm saving an image on the clipboard as a filename specified in the adjacent cell.

It's kind of convoluted I know :)

What I have done as a kludgearound is write a .wsf file telling windows to send an enter keystroke 1,000 times. It's klunky but it works - I just know there's a slicker way to do it!
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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