save sheet only

orsm6

Active Member
Joined
Oct 3, 2012
Messages
496
Office Version
  1. 365
Platform
  1. Windows
hi all - my macro works well and saves the entire workbook, but i need it to save only either the active sheet or sheet named PCR Form. how can i modify the code below? i tried changing to ActiveSheet but it still saved the whole book.

Code:
Option Explicit
Sub SaveFile()
    Dim savepath As String
    Dim Fname As String
    Fname = Worksheets("Lists").Cells(1, 10).Value
    savepath = "\\mdzausutwfnp001\Shardata\Change Management\Plant Change Requests\Submitted PCRs\"
    savepath = savepath & Fname & "\"
    If Dir(savepath, vbDirectory) = "" Then
        MkDir savepath
    End If
    Fname = Fname & " " & Format(Now(), "dd.mmm.yy hhmm AMPM") & ".xlsm"
    ActiveWorkbook.SaveAs savepath & "\" & Fname

'removes upload button after the first time the PCR is submitted and saved
ActiveSheet.Shapes("Picture 36").Visible = False
ActiveSheet.Shapes("TextBox 37").Visible = False

'shows save icon after first upload to register
ActiveSheet.Shapes("Picture 43").Visible = True
ActiveSheet.Shapes("TextBox 49").Visible = True

TIA
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You can't save a sheet by itself, only a workbook. An option is to copy the sheet to a new workbook and save the new workbook.
 
Upvote 0
You can't save a sheet by itself, only a workbook. An option is to copy the sheet to a new workbook and save the new workbook.
ahh ok, that makes sense. Thanks Mark I'll look into changing my approach.
 
Upvote 0
Thanks Mark I'll look into changing my approach.

All you need to do is add the line
VBA Code:
 Worksheets("Lists").Copy
above the line below
VBA Code:
ActiveWorkbook.SaveAs savepath & "\" & Fname
 
Upvote 0
All you need to do is add the line
VBA Code:
 Worksheets("Lists").Copy
above the line below
VBA Code:
ActiveWorkbook.SaveAs savepath & "\" & Fname
actually... when i did that - i get the prompt to continue to save as a macro enabled workbook or not. is there a way around this to 'default' saving as a macro book or user has to click yes?

the macro then crashes into debug.
 
Upvote 0
I don't get that prompt (and I wouldn't until the next line in the code).

What I did need to do is
a) remove the bit in red below as you are already adding a "\" at the end of
VBA Code:
savepath = savepath & Fname & "\"
Rich (BB code):
ActiveWorkbook.SaveAs savepath & "\" & Fname

b) I added the fileformat (i.e. the 52 below) so it ended up as
VBA Code:
    Worksheets("Lists").Copy
    ActiveWorkbook.SaveAs savepath & Fname, 52
 
Upvote 0
I don't get that prompt (and I wouldn't until the next line in the code).

What I did need to do is
a) remove the bit in red below as you are already adding a "\" at the end of
VBA Code:
savepath = savepath & Fname & "\"
Rich (BB code):
ActiveWorkbook.SaveAs savepath & "\" & Fname

b) I added the fileformat (i.e. the 52 below) so it ended up as
VBA Code:
    Worksheets("Lists").Copy
    ActiveWorkbook.SaveAs savepath & Fname, 52
thanks Mark.... do i only remove the "\" from the ActiveWorkbook line?

i have only changed that one and the macro now works.
the only reason i ask, is for some reason when i try to open the new file created in the new folder it says the file doesn't even exist. And it seems that I can't delete the folder that the macro created haha.



so i am not sure if this is a macro issue or an IT thing.
 
Upvote 0
Comment out the
VBA Code:
ActiveWorkbook.SaveAs savepath & Fname, 52
and replace it with
VBA Code:
Debug.Print savepath & Fname

Then run your code and check in the Immediate window if the filepath looks correct.
 
Upvote 0
Comment out the
VBA Code:
ActiveWorkbook.SaveAs savepath & Fname, 52
and replace it with
VBA Code:
Debug.Print savepath & Fname

Then run your code and check in the Immediate window if the filepath looks correct.
creates folder.... creates new workbook (book1) does not go all the way thru to save it with filename etc.
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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