using two cell references to make up the save as file name

J

Johnnyboy5

How do I use two cells to make up the file save name.

eg. A1 and D1 (what ever)

Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)


mydrive = "H:"
mydir = "Temp"
myname = Sheets("sheet1").Range("a1")
ms = mydrive & "\" & mydir & "\" & myname & Format$(Date, " dd-mm-
yyyy") & "xls"
ActiveWorkbook.SaveCopyAs Filename:=ms







' Place the current files path and filename in the titlebar:
Windows(1).Caption = ActiveWorkbook.FullName



' Place your own application name in the titlebar:
Application.Caption = "SPICE SHEET FOLDER"





Cancel = True
ActiveWorkbook.Saved = True
msg = MsgBox("The workbook has been saved as " & ms, vbInformation +
vbOKOnly, "Save As")
Application.DisplayFullScreen = False
End Sub
 
F

FSt1

How do I use two cells to make up the file save name.

eg.   A1   and  D1   (what ever)

Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

mydrive = "H:"
mydir = "Temp"
myname = Sheets("sheet1").Range("a1")
ms = mydrive & "\" & mydir & "\" & myname & Format$(Date, " dd-mm-
yyyy") & "xls"
ActiveWorkbook.SaveCopyAs Filename:=ms

' Place the current files path and filename in the titlebar:
      Windows(1).Caption = ActiveWorkbook.FullName

      ' Place your own application name in the titlebar:
      Application.Caption = "SPICE SHEET FOLDER"

Cancel = True
ActiveWorkbook.Saved = True
msg = MsgBox("The workbook has been saved as " & ms, vbInformation +
vbOKOnly, "Save As")
Application.DisplayFullScreen = False
End Sub

hi
use the ampersand concatenater.
you can concatenate as many cells as you want.

Sub myname()
Dim mn As String
mn = Range("A2").Value & Range("B2").Value
MsgBox mn
End Sub

regards
FSt1
 
J

Johnnyboy5

hi
use the ampersand concatenater.
you can concatenate as many cells as you want.

Sub myname()
Dim mn As String
mn = Range("A2").Value & Range("B2").Value
MsgBox mn
End Sub

regards
FSt1

thanks

added your answer to the macro, the only thing I would like to add is
that there is a "space" between A2 and B" in the file name - eg.
NAME "" 1234556

then I am done !

thanks john




Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

mydrive = "H:"
mydir = "Temp"
myname = Sheets("sheet1").Range("a1").Value & Range("a3").Value
ms = mydrive & "\" & mydir & "\" & myname & ".xls"
ActiveWorkbook.SaveCopyAs Filename:=ms







' Place the current files path and filename in the titlebar:
Windows(1).Caption = ActiveWorkbook.FullName



' Place your own application name in the titlebar:
Application.Caption = "SPICE SHEET FOLDER"





Cancel = True
ActiveWorkbook.Saved = True
msg = MsgBox("The workbook has been saved as " & ms, vbInformation +
vbOKOnly, "Save As")
Application.DisplayFullScreen = False
End Sub
 
J

Johnnyboy5

hi
use the ampersand concatenater.
you can concatenate as many cells as you want.

Sub myname()
Dim mn As String
mn = Range("A2").Value & Range("B2").Value
MsgBox mn
End Sub

regards
FSt1

Sorted - thanks VM.

Johnnyboy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top