Results 1 to 3 of 3

Thread: [RESOLVED] What Is The .InitDir Equivalent In Word VBA

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Resolved [RESOLVED] What Is The .InitDir Equivalent In Word VBA

    I have a piece of VBA code (that I got from here) which opens up Word's SaveAs dialog box and blanks out the name of the file so that the user must type in a new file name. The document is a template and I don't want them overlaying it once it gets its Bookmarks populated with data sent to it from my VB screen.

    All of that works fine. I submitted my code to our QA department last Thursday, and got back a bug sheet this morning. One of the items on it was that the SaveAs dialog opened in the App.Path of the application (which it is supposed to), and since the Word document is displayed there, there is nothing to prevent the user from simply selecting it as the filename, thus overlaying the template. So, my new spec is to open the SaveAs dialog defaulted to the root of C:\

    I know how to do that with a CommonDialog control, but not the Word SaveAs dialog.

    What is the equivlent to .InitDir in Word VBA?

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: What Is The .InitDir Equivalent In Word VBA

    Dunno if this is a help or not...

    From Help files in word VBA
    InitialFileName Property
    See AlsoApplies ToExampleSpecificsSet or returns a String representing the path and/or file name that is initially displayed in a file dialog box. Read/write.

    expression.InitialFileName
    So instead of erasing the whole initial filename (as I think you have from your previous posts) put in the path to show instead with no filename.

    I ran a quick test and seems to work.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: What Is The .InitDir Equivalent In Word VBA

    Quote Originally Posted by Ecniv
    Dunno if this is a help or not...


    So instead of erasing the whole initial filename (as I think you have from your previous posts) put in the path to show instead with no filename.

    I ran a quick test and seems to work.
    Bee-u-tee-ful! Works like a champ. Thanks Ecniv!
    VB Code:
    1. Sub FileSaveAs()
    2. On Error GoTo ErrTrap
    3.   Dim strFileAs As String
    4.   With Application.FileDialog(msoFileDialogSaveAs)
    5.     'based on Ecniv post, I changed
    6.     .InitialFileName = ""
    7.     'to
    8.     .InitialFileName = "c:\"
    9.     'and it does exactly what I need
    10.     .Show
    11.     strFileAs = .SelectedItems.Item(1)
    12.   End With
    13.   ActiveDocument.SaveAs strFileAs
    14.   Exit Sub
    15. ErrTrap:
    16. End Sub
    Now, it is back to the rest of the list, and then ship back to QA.

Posting Permissions

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



Click Here to Expand Forum to Full Width