Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Posts
    304
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What's wrong with this code? (VB 6.3)

    (Edited by HansV to provide link to post - see <!help=19>Help 19<!/help>)

    This is a continuation of an old post of mine (<post#=403489>post 403489</post#>). What is wrong with the code below?

    With Dialogs(wdDialogFileSaveAs)
    .Name = "condorpubliccommonengineeringWorkOrders" & ActiveDocument.Bookmarks("Name").Range.Text & ActiveDocument.Bookmarks("Date").Range.Text
    .Format = wdFormatDocument
    .Show
    End With

    If I leave the Bookmark references off of the .Name argument, then it points to the correct path with no problem. However, if I include the bookmark references, it pulls the correct bookmarked information, but the path is not right (it points to the default Templates folder for the hard drive, since the originating document is a Word template). Somehow it's not concatenating the information properly.

    Thanks for the help - Sat.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: What's wrong with this code? (VB 6.3)

    There is nothing intrinsically wrong with the code, but there might well be a problem with the result. The bookmark name "Date" makes me suspect that it contains a date value. If you concatenate this in the filename argument, you have a problem, for a file name cannot contain / characters. If so, you could replace

    ActiveDocument.Bookmarks("Date").Range.Text

    with

    Replace(ActiveDocument.Bookmarks("Date").Range.Tex t, "/", "")

    You can also test what's happening in the original code by changing it to

    Dim strName As String
    strName = "Cocuments and SettingsHansMijn documentenExcel-bestanden" & ActiveDocument.Bookmarks("Name").Range.Text & ActiveDocument.Bookmarks("Date").Range.Text
    Debug.Print strName
    With Dialogs(wdDialogFileSaveAs)
    .Name = strName
    .Format = wdFormatDocument
    .Show
    End With

    The name to be used will be displayed in the Immediate window.

  3. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Posts
    304
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What's wrong with this code? (VB 6.3)

    Thanks Hans for the response.

    I don't think that there is a problem with the Date bookmark for two reasons. First, I formatted the date field to contain dashes instead of slashes because I anticipated it might be a problem, and second because the bookmarked information IS successfully pulled into the File Name field, but the path just gets wonky on me upon trying to add that extra information. Even if I get rid of the bookmarked information all together and try to add some sort of plain text to the end of it , like this.....

    With Dialogs(wdDialogFileSaveAs)
    .Name = "condorpubliccommonengineeringWorkOrders" & "Satiria"
    .Format = wdFormatDocument
    .Show
    End With

    ....it will put "Satiria" in the File Name field, but the path changes on me, which leads me to believe that either you can't do what I'm trying to do or that I've got my code wrong.

    If you run this macro on your PC (but with a relevant path, obviously) do you get successful results?

    Thanks again.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: What's wrong with this code? (VB 6.3)

    It works OK for me. I tested the code with a path on my PC that is different from the default document path for Word. The Save As dialog opened in the specified folder, with "Satiria" as proposed file name.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: What's wrong with this code? (VB 6.3)

    Default templates folder? That's strange. Either it's the last place you saved, or there is something wrong with the code. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Although I find using .Name to be reliable, you also can attack on two other fronts and see if they help:

    ChangeFileOpenDirectory path

    Options.DefaultFilePath(wdCurrentFolderPath) = path

    If you try one or both of these with your server path before the With Dialogs line, does it help?

Posting Permissions

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