ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Incomplete SaveAs name (https://www.excelbanter.com/excel-programming/279335-incomplete-saveas-name.html)

Robert[_14_]

Incomplete SaveAs name
 
[Xl97] This piece of code is to copy 2 sheets ('Data' and 'Selection')
to a new workbook and name and save the new book to a path and with a
name from the 'Selection' sheet of the new workbook. The path is in
'Selection' G2 and the name in B2. It produces the copy workbook, saves
it using the correct path but only uses the date as the file name, and
does not include the identifier in B2.
G2 reads E:\ELS\Inspections\
B2 reads ELSpilot

Sheets(Array("Data", "Selection")).Select
Sheets(Array("Data", "Selection")).Copy

ActiveWorkbook.SaveAs FileName:= _
Sheets("Selection").Range("G2") & Range("B2") & _
Format(Now(), " DD.MM.YY") & ".xls"

--
Robert

Anders S

Incomplete SaveAs name
 
Robert,

Range B2 refers to the active sheet, which may not be sheet "Selection".

Try
fileName = Sheets("Selection").Range("G2") & Sheets("Selection").Range("B2")
& _
Format(Now(), " DD.MM.YY") & ".xls"

HTH
Anders Silvén

"Robert" skrev i meddelandet
...
[Xl97] This piece of code is to copy 2 sheets ('Data' and 'Selection')
to a new workbook and name and save the new book to a path and with a
name from the 'Selection' sheet of the new workbook. The path is in
'Selection' G2 and the name in B2. It produces the copy workbook, saves
it using the correct path but only uses the date as the file name, and
does not include the identifier in B2.
G2 reads E:\ELS\Inspections\
B2 reads ELSpilot

Sheets(Array("Data", "Selection")).Select
Sheets(Array("Data", "Selection")).Copy

ActiveWorkbook.SaveAs FileName:= _
Sheets("Selection").Range("G2") & Range("B2") & _
Format(Now(), " DD.MM.YY") & ".xls"

--
Robert




Henry[_4_]

Incomplete SaveAs name
 
Robert,

Try

Private Sub Mysub()
With Sheets("Selection")
ActiveWorkbook.SaveAs Filename:= _
.Range("G2").Value & .Range("B2").Value & _
" " & Format(Date, "DD.MM.YY") & ".xls"
End With

End Sub






"Robert" wrote in message
...
[Xl97] This piece of code is to copy 2 sheets ('Data' and 'Selection')
to a new workbook and name and save the new book to a path and with a
name from the 'Selection' sheet of the new workbook. The path is in
'Selection' G2 and the name in B2. It produces the copy workbook, saves
it using the correct path but only uses the date as the file name, and
does not include the identifier in B2.
G2 reads E:\ELS\Inspections\
B2 reads ELSpilot

Sheets(Array("Data", "Selection")).Select
Sheets(Array("Data", "Selection")).Copy

ActiveWorkbook.SaveAs FileName:= _
Sheets("Selection").Range("G2") & Range("B2") & _
Format(Now(), " DD.MM.YY") & ".xls"

--
Robert




Robert[_14_]

Incomplete SaveAs name
 
Henry - many thanks it solved the problem

Robert

n message , Henry
writes
Robert,

Try

Private Sub Mysub()
With Sheets("Selection")
ActiveWorkbook.SaveAs Filename:= _
.Range("G2").Value & .Range("B2").Value & _
" " & Format(Date, "DD.MM.YY") & ".xls"
End With

End Sub




All times are GMT +1. The time now is 10:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com