Consulting

Results 1 to 12 of 12

Thread: Solved: File Save As

  1. #1
    VBAX Regular
    Joined
    Sep 2008
    Posts
    20
    Location

    Solved: File Save As



    Hi Guys,

    I have done a search, but can't seem to find anything that helps me.

    I've attached a file for ease of explanation.

    I'm trying to compile a forecast budget master file for my branches.

    I'm have a bit of trouble trying to get the file to save as another filename based on the branch that a user selects.

    The idea is that when any user opens the master file (I have made this a readonly file), a userform will force them to select a branch that they will work on (along with other options). When the OK button is pressed, I want to automatically save the file as another filename, based on the branch that they select. I want to save this file based on a naming convention that we have at this company.

    The code for the ok button is :

    ActiveWorkbook.SaveAs FileName:=Range("S2").Value

    This doesn't seem to have any effect on the filename.
    Is it because S2 refers to a formula?

    Please help.

    Thanks in advance for you time and effort and any help will be greatly appreciated.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The problem is that the SaveAsUI argument is only true if the Save as is done from a dialog, the UI part of the name, not if you issue a SaveAs command.

    You will need some more logic to handle that situation through you BeforeSave code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Sep 2008
    Posts
    20
    Location
    Sorry, Now I'm confused - I'm not a VBA regular by any means and I have no idea what to do now... What type of logic are you refering to?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well who wrote the rest of the code that you have then?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Sep 2008
    Posts
    20
    Location
    That was me, though it is hardly from a level of understanding though - just bits that i have picked up from the net. Copying and pasting and trying to adapt to my needs - that's all.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    See if this works.

    Add this code into one of the standard code modules

    [vba]

    Public SaveName As String
    [/vba]

    and change the form code OK procedure to

    [vba]


    Private Sub cmdOK_Click()

    frmSelect.Hide
    SaveName = Range("S2").Value
    ActiveWorkbook.Save

    End Sub
    [/vba]

    and then change the CustomeSave procedure to

    [vba]

    Private Sub CustomSave(Optional SaveAs As Boolean)
    Dim ws As Worksheet, aWs As Worksheet, newFname As String
    'Turn off screen flashing
    Application.ScreenUpdating = False

    'Record active worksheet
    Set aWs = ActiveSheet

    'Hide all sheets
    Call HideAllSheets

    'Save workbook directly or prompt for saveas filename
    If SaveAs = True Then
    newFname = Application.GetSaveAsFilename( _
    fileFilter:="Excel Files (*.xls), *.xls")
    If Not newFname = "False" Then ThisWorkbook.SaveAs newFname
    ElseIf SaveName <> "" Then
    ThisWorkbook.SaveAs SaveName
    SaveName = ""
    Else
    ThisWorkbook.Save
    End If

    'Restore file to where user was
    Call ShowAllSheets
    aWs.Activate

    'Restore screen updates
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Sep 2008
    Posts
    20
    Location
    Thanks LD - appreciated - will try now...

  8. #8
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,191
    Location
    [VBA]Private Sub cmdOK_Click()

    frmSelect.Hide
    ActiveWorkbook.SaveCopyAs Range("S2").Value & ".xls"

    End Sub[/VBA]
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  9. #9
    VBAX Regular
    Joined
    Sep 2008
    Posts
    20
    Location
    XLD - sorry for being a pain, Where should I insert the customsave procedure? Into the form? or one of modules?

  10. #10
    VBAX Regular
    Joined
    Sep 2008
    Posts
    20
    Location
    Georgiboy,

    How do i now activate this workbook directly?

  11. #11
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,191
    Location
    How do you mean?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  12. #12
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,191
    Location
    Do you mean like this. Once you have saved the copy you can open it, then activate it, then write to it from the master sheet macros:

    [VBA]Workbooks.Open (Range("S2") & ".xls")
    Windows(Range("S1") & ".xls").Activate
    ActiveWorkbook.Sheets("Instructions").Range("A1").Value = "Hello"[/VBA]

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •