Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-09-2022, 05:19 AM
gmayor's Avatar
gmayor gmayor is offline Word save in folder bookmark Windows 10 Word save in folder bookmark Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It is certainly possible, but you haven't said what you wish to use as the document name. In the example below the document will be saved in a folder named from a numeric value in the bookmark with the name filename.docx.
Code:
Sub SaveAsBM()

'Graham Mayor - https://www.gmayor.com - Last updated - 09 Mar 2022 

Dim oBM As Bookmark
Dim sPath As String
Dim bFound As Boolean
    For Each oBM In ActiveDocument.Bookmarks
        If LCase(oBM.Name) = "code" Then
            If IsNumeric(oBM.Range.Text) = True Then
                sPath = "C:\Server\" & oBM.Range.Text & "\"
                CreateFolders sPath
                ActiveDocument.SaveAs sPath & "filename.docx" 'change filename as required
                bFound = True
            Else
                MsgBox "Bookmark content is not numeric", vbCritical
                GoTo lbl_Exit
            End If
            Exit For
        End If
    Next oBM
    If Not bFound = True Then
        MsgBox "Bookmark not present", vbCritical
    End If
lbl_Exit:
    Set oBM = Nothing
    Exit Sub
End Sub

Private Function CreateFolders(strPath As String)
Dim strTempPath As String
Dim lng_Path As Long
Dim VPath As Variant
Dim oFSO As Object
Dim i As Integer
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    VPath = Split(strPath, "\")
    If Left(strPath, 2) = "\\" Then
        strPath = "\\" & VPath(2) & "\"
        For lng_Path = 3 To UBound(VPath)
            strPath = strPath & VPath(lng_Path) & "\"
            If Not oFSO.FolderExists(strPath) Then MkDir strPath
        Next lng_Path
    Else
        strPath = VPath(0) & "\"
        For lng_Path = 1 To UBound(VPath)
            strPath = strPath & VPath(lng_Path) & "\"
            If Not oFSO.FolderExists(strPath) Then MkDir strPath
        Next lng_Path
    End If
lbl_Exit:
    Set oFSO = Nothing
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't save Word 2019 doc to original folder - can you help please? frustratedphil Word 1 01-06-2019 11:11 AM
Word save in folder bookmark Save all docs to pdf in specified folder loki005 Word VBA 4 10-25-2018 02:18 PM
macro to save as pdf with name from bookmark pamtupac Word VBA 3 06-06-2017 08:23 PM
Word save in folder bookmark Macro to save as pdf with ability to choose save as folder rvessio Word VBA 4 07-25-2016 12:37 PM
Word save in folder bookmark Default Save AS File Name from Bookmark xscotsmanx Word VBA 1 07-17-2011 12:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft