PDA

View Full Version : save a workbook and giving it an initial file name based on a cell value



jammer6_9
12-04-2011, 02:43 PM
I was trying to save a workbook and giving it an initial file name based on a cell value but :banghead: :banghead: :banghead:


Sub Extract_JV()
Dim wb As New Workbook
Dim sFile As Variant

Sheets("JV").Visible = True

inti = MsgBox("JV worksheet will be process, do you want to continue?", vbYesNo + vbQuestion, "ofsjcr")
If inti = 6 Then

Sheets(Array("JV")).Copy


Set wb = ActiveWorkbook
'here i want to give an initial filename based on the value of sheet("JV").range("f47")
sFile = Application.GetSaveAsFilename(InitialFileName:=wb.Sheets("JV").Range("F47").Value, fileFilter:="Microsoft Office Excel Workbook (*.xls), *.xls", Title:="Save workbook to..")

If sFile <> False Then
ActiveWorkbook.SaveAs Filename:=sFile
ThisWorkbook.Saved = True


End If


End If

mancubus
12-04-2011, 04:24 PM
it worked for me...

what error does it throw?

jammer6_9
12-04-2011, 08:23 PM
Actualy no error but it does not give what i wanted to have which give the initial file name based on the cell value specified.

monarchd
12-06-2011, 02:56 PM
Give this a try:

Sub SvMe()

Dim newFile As String, fName As String
Dim SaveFormat As Long
Dim TempFilePath
Dim inti


Sheets("JV").Visible = True

inti = MsgBox("JV worksheet will be process, do you want to continue?", vbYesNo + vbQuestion, "ofsjcr")
If inti = 6 Then

Sheets(Array("JV")).Copy

'Save the new workbook at this file path location
TempFilePath = "C:" & "\"

On Error Resume Next

fName = Sheets("JV").Range("F47").Text

newFile = TempFilePath & fName

If fName <> False Then
ActiveWorkbook.SaveAs Filename:=newFile
ThisWorkbook.Saved = True
End If
End If


End Sub