Consulting

Results 1 to 5 of 5

Thread: Use string to set folder path.

  1. #1

    Lightbulb Use string to set folder path.

    Hy everyone, I have the following problem with a VBA macro written in Microsoft Word 2010:

    Option Explicit
    Sub BAAR()

    Dim fisword As String
    Dim folder As String
    Dim primit As String
    Dim cinci As String
    Dim cinci1 As String
    Dim raport As String
    Dim BAAR As String
    Dim nr As String
    Dim marca As String
    Dim data As String
    Const strDrive As String = "D:\MIHAI\DOSARE\BAAR\"

    raport = Trim(ActiveDocument.BuiltInDocumentProperties("Title").Value)
    BAAR = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32)
    nr = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("Company").Value), Chr(150), "")
    marca = ActiveDocument.BuiltInDocumentProperties("Comments").Value
    data = ActiveDocument.BuiltInDocumentProperties("Content status").Value
    cinci = Right(Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Val ue), "/", ".") & Chr(32), 6)
    cinci1 = Replace(cinci, " ", "")

    primit = "BAAR-Dosarxxx" & "_" & cinci1 & "-" & data & " Mihai"
    fisword = "R" & raport & "_" & BAAR & marca & " " & nr
    folder = "BAAR-Dosar" & raport & "_" & cinci1 & " " & nr & " " & marca & "-" & data
    Name strDrive & primit As strDrive & folder


    ' the problem is at the next two lines: instead of saving the next 2 files (word and pdf) in the path strdrive & folder, the macro saves the 2 documents in path strDrive with name folder & fisword ( I need the path to be strDrive & folder and name fisword)

    ActiveDocument.SaveAs2 strDrive & folder & fisword & ".docx"
    ActiveDocument.ExportAsFixedFormat OutputFileName:=strDrive & folder & fisword & ".pdf", _


    ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=False, _
    OptimizeFor:=wdExportOptimizeForPrint, _
    Range:=wdExportAllDocument, From:=1, To:=1, _
    Item:=wdExportDocumentContent, _
    IncludeDocProps:=True, _
    KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateHeadingBookmarks, _
    DocStructureTags:=True, _
    BitmapMissingFonts:=True, _
    UseISO19005_1:=False

    lbl_Exit:
    Exit Sub
    End Sub



    I wish everybody a Happy New Year !

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    See if adding ChDir helps

    ChDir strDrive & folder
    
    ActiveDocument.SaveAs2   fisword & ".docx"
    ActiveDocument.ExportAsFixedFormat OutputFileName:= fisword & ".pdf",
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Hy Paul,
    I tried with ChDir and same results, it saves under initial strDrive path, it doesnt take into consideration folder string after strDrive.
    Thanks anyway.

  4. #4
    The problem arises because you have not inserted a path separator (Chr(92) or "\") between the path and the filename and so the folder segment is added to the filename.
    You will also need to create the folder if it doesn't exist. There is code on my web site to facilitate that.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Thanks a lot man.

Posting Permissions

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