Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #14  
Old 10-30-2022, 06:39 PM
BrianHoard BrianHoard is offline Word - position document Windows 10 Word - position document Office 2019
Advanced Beginner
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Okay, I think we're getting closer. I modified your SaveAsBM script as below, replacing the InputBox with code for getting the value of the bookmark named "CodiClient"

It tested fine for me, creating the folder named 11241, and saving the document as a PDF. But the PDF wouldn't open for me, but I trust it's working for you, or you know how to make that part work.

Let me know if this is getting closer to your goal.

Code:
Sub SaveAsBM()
  Dim oBM As String
  Dim sPath As String
  
  Dim bm As Bookmark
  Dim bmName As String
  Dim bmValue As String
  Dim rng_bm As Range
  Dim rng_expanded As Range
  Dim bmCheck As Boolean
  
  bmName = "CodiClient"
  sPath = "C:\Server"
      
  '  oBM = InputBox("RECEPTE", "ENTRA EL CODI DEL PACIENT", "")
  
  ' Store bookmark value for new folder name.
  For Each bm In ActiveDocument.Bookmarks
    If bm.Name = bmName Then
      Set rng_bm = bm.Range
      
      If rng_bm.Start = rng_bm.End Then
        Set rng_expanded = rng_bm
        rng_expanded.MoveEndWhile cset:="0123456789"
        bmValue = rng_expanded.Text
        sPath = (sPath & "\" & bmValue & "\")
        bmCheck = True
      End If
    End If
  Next bm
  
  If bmCheck = True Then
    Debug.Print ("Creating folder: " & sPath)
    CreateFolders sPath
    ActiveDocument.SaveAs sPath & "recepte" & Format(Now, "yyyymmdd hhnnss") & ".pdf"
    bFound = True
  Else
    Call MsgBox(prompt:=("Unable to find bookmark, " & bmName), buttons:=vbCritical)
  End If

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word - position document Can I make Word remember the window size and position for each document? Jennifer Murphy Word 4 02-20-2023 06:36 PM
Changing Caption Position on Whole Document at once Alexandarale Word Tables 1 11-15-2020 06:56 PM
Word - position document Copy selected text from one document and paste to new document in same position on the page gasparik Word VBA 1 05-11-2020 05:41 AM
Starting a document, returning to last position glennnall Word 0 10-08-2017 10:09 AM
Word - position document VBA: how can I know the position on a document? tinfanide Excel Programming 3 02-27-2012 03:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:17 AM.


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