Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2016, 08:54 AM
derekcentrico derekcentrico is offline Newb needing VBA solution to change formatting Windows 7 Newb needing VBA solution to change formatting Office 2010 (Version 14.0)
Novice
Newb needing VBA solution to change formatting
 
Join Date: Jul 2010
Posts: 6
derekcentrico is on a distinguished road
Default Newb needing VBA solution to change formatting

I'm totally ignorant to this stuff so please forgive me in advance.

I made a quick form that uses bookmarks to copy the data to the various pages. However, I've run into a few hiccups doing so with the font color and font type.

What could I add to this command that will change the font to Arial and the font color to black? I'd like it to the the whole body and headers/footers if possible.

Current bookmark removing VBA found on another website:
Code:
Sub removebookmarks()
Dim bkm As Bookmark
For Each bkm In ActiveDocument.Bookmarks
bkm.Delete
Next bkm
End Sub
I tried this combo and it didn't work.



Code:
Sub removebookmarks()
Dim bkm As Bookmark
For Each bkm In ActiveDocument.Bookmarks
bkm.Delete
Next bkm
End Sub
ActiveDocument.Font.ColorIndex = wdBlack
With ActiveDocument.Font 
 .Name = "Arial" 
End With
Any help is appreciated.
Reply With Quote
  #2  
Old 11-28-2016, 02:57 PM
macropod's Avatar
macropod macropod is offline Newb needing VBA solution to change formatting Windows 7 64bit Newb needing VBA solution to change formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by derekcentrico View Post
I made a quick form that uses bookmarks to copy the data to the various pages.
There is no evidence of that in the code you posted - all it does regarding bookmarks is to delete them. It's not apparent what point that serves.
Quote:
Originally Posted by derekcentrico View Post
What could I add to this command that will change the font to Arial and the font color to black? I'd like it to the the whole body and headers/footers if possible.
The proper way to modify font attributes and the like, especially when you're dealing with an entire document, is to redefine the Styles it uses or to define and apply an appropriate Style - not to use brute-force overriding of the existing Style definitions. Assuming your existing document is using Styles properly, that obviates any concerns regarding headers & footers.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-29-2016, 05:21 AM
derekcentrico derekcentrico is offline Newb needing VBA solution to change formatting Windows 7 Newb needing VBA solution to change formatting Office 2010 (Version 14.0)
Novice
Newb needing VBA solution to change formatting
 
Join Date: Jul 2010
Posts: 6
derekcentrico is on a distinguished road
Default

Yeah, that's all the original code should do is delete the bookmarks. I used bookmarks and cross referencing, Alt + F9, to generate my crazy pages with repetitive information.

Anyway, I'm ignorant on styles and VBA. Is there a simple way to keep the entire document locked down to Arial and black color?

For some reason, my headers and other areas end up defaulting to Calibri and gray sometimes. I edited the plain text control properties for each box to be black and Arial. But, this doesn't always hold true. It'll end up changing anyway.

Sorry. Really low skilled here with Word.
Reply With Quote
  #4  
Old 11-29-2016, 08:51 AM
macropod's Avatar
macropod macropod is offline Newb needing VBA solution to change formatting Windows 7 64bit Newb needing VBA solution to change formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

If you delete bookmarks, any cross-references to them will break. If you're starting off with a document using the correct font settings, per their Style definitions, there shouldn't be any need to mess with them afterwards. The problems you're having with things reverting to gray/Calibri suggests the Style definitions that exist in the document have been overridden with hard formatting. That's just asking for trouble.

To understand Styles, see:
http://shaunakelly.com/word/styles/stylesms.html
http://www.shaunakelly.com/word/styl...sonstyles.html
http://www.addbalance.com/usersguide/styles.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-05-2016, 01:40 PM
derekcentrico derekcentrico is offline Newb needing VBA solution to change formatting Windows 7 Newb needing VBA solution to change formatting Office 2010 (Version 14.0)
Novice
Newb needing VBA solution to change formatting
 
Join Date: Jul 2010
Posts: 6
derekcentrico is on a distinguished road
Default

Thanks for that info. I got most of the styles working in the document (woo-hoo).

However, another problem reared its ugly head.

I have 27 fields that repeat throughout 15 pages. I created a table on the first page to input the data. The table uses bookmarks and cross-references to the bookmarks to populate the fields.

I used the code discussed above, and again here, to remove the bookmarks so I could delete the input page before saving the final document.

Unfortunately, without the bookmarks data seems to be lost when clicking Print. It saves fine. But, it changes to "Error! Reference source not found" when printing. Everything changes to that.

Code used:
Code:
Sub removebookmarks()
Dim bkm As Bookmark
For Each bkm In ActiveDocument.Bookmarks
bkm.Delete
Next bkm
End Sub
Any thoughts on a way to convert so I don't lose all the final data? The bookmarks save me like 2 hours building the documents literally. But this part is a real downer because I have to have it saved for later use/review without my table.
Reply With Quote
  #6  
Old 12-05-2016, 03:56 PM
macropod's Avatar
macropod macropod is offline Newb needing VBA solution to change formatting Windows 7 64bit Newb needing VBA solution to change formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by derekcentrico View Post
However, another problem reared its ugly head.

...

I used the code discussed above, and again here, to remove the bookmarks so I could delete the input page before saving the final document.

Unfortunately, without the bookmarks data seems to be lost when clicking Print. It saves fine. But, it changes to "Error! Reference source not found" when printing. Everything changes to that.
Well, I did warn you:
Quote:
Originally Posted by macropod View Post
If you delete bookmarks, any cross-references to them will break.
Yes, there are ways around this but, frankly, I can't see what is achieved by deleting the bookmarks. Why not just leave them there and save your self the grief???
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 12-05-2016, 04:00 PM
derekcentrico derekcentrico is offline Newb needing VBA solution to change formatting Windows 7 Newb needing VBA solution to change formatting Office 2010 (Version 14.0)
Novice
Newb needing VBA solution to change formatting
 
Join Date: Jul 2010
Posts: 6
derekcentrico is on a distinguished road
Default

Yeah, you warned me but I was dumb and trying to solve this as quickly as possible.

Is there anyway to just delete my table (literally all of page 1) and not have those bookmarks drop their data when it goes away?
Reply With Quote
  #8  
Old 12-05-2016, 04:13 PM
macropod's Avatar
macropod macropod is offline Newb needing VBA solution to change formatting Windows 7 64bit Newb needing VBA solution to change formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

This is the first time you've mentioned deleting the table; you previously mentioned deleting only the bookmarks. If you delete a table, all the bookmarks in it will be deleted at the same time, obviating the need to delete the bookmarks via a separate loop.

You can avoid the "Error! Reference source not found" result by not updating fields before printing (this is a Word option, set via File|Options|Display) but that won't prevent other actions from having the same effect, or you could unlink the cross-references in the document body via code like:
ActiveDocument.Fields.Unlink
Additional code would be required for unlinking in other story ranges. Do note that this will unlink all fields in the document body, including Tables of Contents, Captions, Hyperlinks, etc. If you want only to unlink cross-references, you would need to implement a loop that individually unlinks REF and PAGEREF fields.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 12-06-2016, 05:36 AM
derekcentrico derekcentrico is offline Newb needing VBA solution to change formatting Windows 7 Newb needing VBA solution to change formatting Office 2010 (Version 14.0)
Novice
Newb needing VBA solution to change formatting
 
Join Date: Jul 2010
Posts: 6
derekcentrico is on a distinguished road
Default

Sadly, I don't know enough about scripting to figure this out.

The only hyperlinks and data referenced as a potential side effect are the bookmarks and cross references that I want to defeat, so whatever I do wouldn't be a negative to anything like that.

I found this online:

Code:
Sub UnlinkBookmarks()
    Dim aFld As Field
        For Each aFld In ActiveDocument.Fields
            If InStr(1, aFld.Code.Text, "LSU_", 1) Then
                'Debug.Print aFld.Code.Text
                aFld.Unlink
            End If
    Next aFld
End Sub
Now I don't care about looking for specific codes.

Anyway, I just stripped down the code to remove the field LSU_ stuff to something like this below to remove any and all cross-references. But, it didn't work. What am I missing to do the removal of the cross-reference while keeping the original data from the bookmark intact at that spot?

Code:
Sub UnlinkBookmarks()
    Dim aFld As Field
        For Each aFld In ActiveDocument.Fields
                aFld.Unlink
            End
    Next aFld
End Sub
Also, just a FYI. I do not have the fields checked to update fields or linked data before printing. The error still occurs.
Reply With Quote
  #10  
Old 12-06-2016, 01:24 PM
macropod's Avatar
macropod macropod is offline Newb needing VBA solution to change formatting Windows 7 64bit Newb needing VBA solution to change formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by derekcentrico View Post
The only hyperlinks and data referenced as a potential side effect are the bookmarks and cross references that I want to defeat, so whatever I do wouldn't be a negative to anything like that.
As I said before, simply deleting the table will delete all the bookmarks associated with it. Accordingly, you wouldn't need your 'removebookmarks' sub or an 'UnlinkBookmarks' sub and your entire code could be reduced to just two lines:
Code:
Sub CleanUp()
ActiveDocument.Fields.Unlink
ActiveDocument.Tables(1).Delete
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 12-12-2016, 12:27 PM
macropod's Avatar
macropod macropod is offline Newb needing VBA solution to change formatting Windows 7 64bit Newb needing VBA solution to change formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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://windowssecrets.com/forums/sho...not-found-quot
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newb needing VBA solution to change formatting newb - search and replace - WILDCARDS - keep original...? Bansaw Word 4 09-01-2016 11:16 AM
Backing up importing & exporting ?? I am a newb Jazz OneNote 0 01-27-2016 10:18 PM
Newb needing VBA solution to change formatting newb - need help automating catalogue production Deeper Office 2 09-09-2015 01:45 AM
Newb needing VBA solution to change formatting Is there a solution to change the recentfilelist programmatically dherr Excel Programming 13 12-02-2014 08:31 AM
NEWB to Macros - formatting exports EC37 Excel Programming 52 06-25-2014 06:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:42 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