![]() |
|
#15
|
|||
|
|||
|
Looping through the bookmarks collection is unnecessary when there is a built-in function to check that a bookmark exists.
So the simplified code should be: Code:
Sub SaveAsBM()
Dim sPath As String: sPath = "C:\Server"
Dim bmName As String: bmName = "CodiClient"
Dim bm As Bookmark
Dim bmValue As String
Dim rng_bm As Range
If ActiveDocument.Bookmarks.Exists(bmName) Then
Set rng_bm = bm.Range
If rng_bm.Start = rng_bm.End Then
rng_bm.MoveEndWhile cset:="0123456789"
bmValue = rng_bm.Text
End If
sPath = (sPath & "\" & bmValue & "\")
Debug.Print ("Creating folder: " & sPath)
CreateFolders sPath
ActiveDocument.SaveAs sPath & "recepte" & Format(Now, "yyyymmdd hhnnss") & ".pdf"
Else
Call MsgBox(prompt:=("Unable to find bookmark, " & bmName), buttons:=vbCritical)
End If
End Sub
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
VBA: how can I know the position on a document?
|
tinfanide | Excel Programming | 3 | 02-27-2012 03:24 PM |