#1
|
|||
|
|||
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 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 |
#2
|
||||
|
||||
Quote:
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] |
#3
|
|||
|
|||
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. |
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
Quote:
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] |
#7
|
|||
|
|||
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? |
#8
|
||||
|
||||
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] |
#9
|
|||
|
|||
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 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 |
#10
|
||||
|
||||
Quote:
Code:
Sub CleanUp() ActiveDocument.Fields.Unlink ActiveDocument.Tables(1).Delete End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
||||
|
||||
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] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 - need help automating catalogue production | Deeper | Office | 2 | 09-09-2015 01:45 AM |
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 |