VBA Save As Pop Up,

StevenTG

New Member
Joined
Jun 12, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to write a macro that runs basically an import file and saves it to a new worksheet, and once it is done running, a save dialogue box comes up, and it saves just the worksheet that has the import data. This is currently my code:

Dim varResult As Variant
Dim ActBook As Workbook

'displays the save file dialog
varResult = Application.GetSaveAsFilename(FileFilter:= _
"Excel Files (*.xlsx), *.xlsx", Title:="Save PO", _
InitialFileName:="\\showdog\service\Service_job_PO\")

'checks to make sure the user hasn't canceled the dialog
If varResult <> False Then
ActiveWorkbook.SaveAs FileName:=varResult, _
FileFormat:=xlWorkbookNormal
Exit Sub
End If



This works but, it saves the whole entire workbook including the macro rather than that one worksheet. Is there a specific coding I can use that saves the current sheet that the import file uses?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If you use the worksheet copy method it creates a new workbook with just that worksheet in it.

This new workbook then becomes the active workbook.

The second line will save and close the workbook using the file name in varResult.

If you don't want to close the new workbook then use this line:

ActiveWorkbook.SaveAs Filename:=varResult

The new workbook will still be the active workbook.

Change the '"worksheetname' to your worksheet name.

VBA Code:
    Worksheets("worksheetname").Copy
    
    ActiveWorkbook.Close SaveChanges:=True, Filename:=varResult
 
Upvote 0
If you use the worksheet copy method it creates a new workbook with just that worksheet in it.

This new workbook then becomes the active workbook.

The second line will save and close the workbook using the file name in varResult.

If you don't want to close the new workbook then use this line:

ActiveWorkbook.SaveAs Filename:=varResult

The new workbook will still be the active workbook.

Change the '"worksheetname' to your worksheet name.

VBA Code:
    Worksheets("worksheetname").Copy
   
    ActiveWorkbook.Close SaveChanges:=True, Filename:=varResult
thanks!
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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