Helen842000
New Member
- Joined
- Mar 28, 2011
- Messages
- 34
Hi all,
I have the following working macro below.
Sub Button1_Click()
ActiveSheet.Unprotect "password"
Dim wbNew As Workbook
Application.DisplayAlerts = False
Worksheets("Page4").Copy
Set wbNew = ActiveWorkbook
With wbNew
With .Worksheets(1).UsedRange
.Value = .Value
End With
.SaveAs "C:\Folder\Folder\Folder\ SheetName.xls"
.Close True
End With
Application.DisplayAlerts = True
End Sub
Currently this macro does the following :-
1) Unprotects the workbook with a known password
2) Copies one worksheet out as current values into a new workbook
3) Saves the new workbook in a network location with the name SheetName.xls
Now for the modification, instead of saving the workbook a fixed name, I would like to name of the file to come from the contents of cells D4 and B2. So something like .SaveAs Filename:="C:\Folder\Folder\" & Range("D4").Value however that just references 1 cell not two.
I have tried several ways to reference the values held in those cells when the file is being saved. However each time I get a debug error.
Any thoughts?
I have the following working macro below.
Sub Button1_Click()
ActiveSheet.Unprotect "password"
Dim wbNew As Workbook
Application.DisplayAlerts = False
Worksheets("Page4").Copy
Set wbNew = ActiveWorkbook
With wbNew
With .Worksheets(1).UsedRange
.Value = .Value
End With
.SaveAs "C:\Folder\Folder\Folder\ SheetName.xls"
.Close True
End With
Application.DisplayAlerts = True
End Sub
Currently this macro does the following :-
1) Unprotects the workbook with a known password
2) Copies one worksheet out as current values into a new workbook
3) Saves the new workbook in a network location with the name SheetName.xls
Now for the modification, instead of saving the workbook a fixed name, I would like to name of the file to come from the contents of cells D4 and B2. So something like .SaveAs Filename:="C:\Folder\Folder\" & Range("D4").Value however that just references 1 cell not two.
I have tried several ways to reference the values held in those cells when the file is being saved. However each time I get a debug error.
Any thoughts?