Consulting

Results 1 to 4 of 4

Thread: Solved: Suggest a file name

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Solved: Suggest a file name

    I have code that I use througout my add-in to bring up a save as dialog. However, I am trying to add it so it suggests a file name but I can't figure out how to do that part. Here is the code that I am using:

    [VBA]Sub SaveCode(Optional ByVal stgDirectory As String = "H:")

    Dim wbFileName As String, stgSelectedDirectory As String, blnShowAlert As Boolean

    On Error GoTo SaveNoDirectory
    ChDrive "H:"
    ChDir stgDirectory 'Change Directory to the users default directory
    SaveNoDirectory:

    'If the user hasn't set a Default Directory
    wbFileName = Application.GetSaveAsFilename

    On Error GoTo SaveBook
    If wbFileName = "False" Then
    blnShowAlert = GetSetting("Business Reporting Today", "General", "Alert-Save", True)
    If blnShowAlert = True Then
    frmErrorAlert.Show
    If frmErrorAlert.cbDontShow Then
    SaveSetting "Business Reporting Today", "General", "Alert-Save", False
    Else
    SaveSetting "Business Reporting Today", "General", "Alert-Save", True
    End If
    Unload frmErrorAlert
    End If
    errUpdateLogFile "SaveCode-NoSave"
    Exit Sub
    End If

    SaveBook:

    'Get the User specified directory
    stgSelectedDirectory = Left(wbFileName, InStrRev(wbFileName, "\") - 1)

    'Check if Directory the user is trying to save in is Read-Only - this part still
    'Doesn't work
    If GetAttr(stgSelectedDirectory) And vbReadOnly Then
    MsgBox "Test"
    End If

    'If the user didn't type the file extension, this will add it
    If Right(wbFileName, 5) = ".xlsx" Then
    ActiveWorkbook.SaveAs wbFileName, FileFormat:=xlNormal
    Else
    ActiveWorkbook.SaveAs wbFileName & ".xlsx", FileFormat:=xlNormal
    End If

    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    GetSaveAsFilename has an Initial Filename property.
    ____________________________________________
    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 Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    how come some code you hit a spacebar and the needed properties will show up but others you need to add a ( for them to show up? Also, how would I know the difference? Maybe, so I can't make this big mistake again?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Don't really know mate. Intellisense works fine for me, I type

    mpFilename = Application.GetSaveAsFilename(

    and all the properties popup, with the next in line being bold. Of course I do have the AUto List Options checked in Tools>Options...>Editor.
    ____________________________________________
    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

Posting Permissions

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