Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2011, 03:31 AM
Dom37 Dom37 is offline Macro VBA "Save as" with bookmarks in file name string Windows XP Macro VBA "Save as" with bookmarks in file name string Office 2003
Novice
Macro VBA "Save as" with bookmarks in file name string
 
Join Date: Oct 2011
Posts: 1
Dom37 is on a distinguished road
Default Macro VBA "Save as" with bookmarks in file name string

Goodmorning, i need create a macro VBA : Save as
my problem is insert in file name string a bookmark present in my active document. I make so:



Code:
Sub SalvaNonConformita()
ChangeFileOpenDirectory "C:\Documenti\"
myDocname = ActiveDocument.Name
ActiveDocument.Bookmarks("CodAnom").Select
pos = InStr(myDocname, ".")
If pos > 0 Then
  myDocname = Left(myDocname, pos - 1)
  myDocname = "NonConformita_" & MyBookmark & ".doc"
  ActiveDocument.SaveAs FileName:=myDocname, FileFormat:=wdFormatDocument, _
  LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="",  _
  ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
  SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
End If
'ActiveDocument.Close
ChangeFileOpenDirectory "C:\Documenti\"
End Sub
where my bookmark is CodAnom

Please help me

Last edited by macropod; 10-31-2011 at 02:04 AM. Reason: Added code tags
Reply With Quote
  #2  
Old 10-31-2011, 02:08 AM
macropod's Avatar
macropod macropod is offline Macro VBA "Save as" with bookmarks in file name string Windows 7 64bit Macro VBA "Save as" with bookmarks in file name string Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Dom,

The problem is that you're referring to the bookmark, not its contents. Try something like:
Code:
Sub SalvaNonConformita()
Dim StrDoc As String, StrPath As String, StrBkMk As String
StrPath = "C:\Documenti\"
With ActiveDocument
  StrDoc = Split(.Name, ".")(0)
  StrBkMk = .Bookmarks("CodAnom").Range.Text
  If StrDoc = .Name Then
    StrDoc = StrPath & "NonConformita_" & StrBkMk & ".doc"
    .SaveAs FileName:=StrDoc, FileFormat:=wdFormatDocument, AddToRecentFiles:=True
  End If
  .Close
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-31-2011, 03:28 AM
macropod's Avatar
macropod macropod is offline Macro VBA "Save as" with bookmarks in file name string Windows 7 64bit Macro VBA "Save as" with bookmarks in file name string Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: http://www.vbaexpress.com/forum/showthread.php?t=39582

For cross-posting etiquette, please read: http://www.excelguru.ca/node/7

Like anyone else, I don't enjoy working out a solution only to find you've been given one (and not let on) somewhere else!!!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable "do you also want to save changes to the document template?" harassalog. wornways Word 30 06-04-2016 02:32 PM
Macro VBA "Save as" with bookmarks in file name string How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM
Macro VBA "Save as" with bookmarks in file name string Launch macro sub after hitting "create pdf" button in word webharvest Word VBA 1 06-29-2011 04:56 PM
How to fix "create bookmarks using headings" as default when saving to PDF using Word ghumdinger Word 0 05-05-2011 02:11 AM
Macro VBA "Save as" with bookmarks in file name string Suppress "do you want to save?" dialog on close rnstewart Excel 2 12-28-2005 04:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:48 PM.


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