Center text in current page
Hello:
I have generated a Word document from code with Visual Basic 2005. I'm using
Word 2003. I want to center a title in the first page (two lines), but only
in this page. I have tried a few method but they didn't work properly. Any
idea?
Thanks. Tag: i, Tag: 112374
next page - section break / insert file
A 2 prong question:
I have a protected template which has 4 different check boxes. If a check
box is checked, I need to insert a section break/next page AFTER the page.
Once I have inserted the break, I then need to insert a file (document) from
our network drive.
This example, I could insert 4 different files to my template.
Not sure how to code appropriately to add the section break or to insert file.
Any help would be appreciated.
Thanks,
Bryan Tag: i, Tag: 112355
page counting macro works one day, but not the next
In a previous post, I asked about methods for linking separate files into a
single document with a single TOC. I was directed away from using Master
documents, and towards using the {RD \f} feature.
This appears to work just fine. I insert the bracket(s), type in the file
name(s), generate the TOC. Of course each file starts page numbering at 1.
From this point, it was a short jump to using a macro created to count the
number of pages in a document and key off of that. I did not devlope this
macro but am using the one provided in the article
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=148
Here's my problem. It works great, at first. I open and close the main
document, happily add more documents, generate a new TOC, update the page
numbers, save, close, open, etc. Then I go home for the day. The next day,
when I try to run the macro (yes, I enabled macros upon opening the
document), having made no changes in any of the documents, the macro won't
run. It hangs up on the first document with the following:
Runtime error '5174'
file could not be found
check spelling, try different file name, etc
File names did not change from the previous day. Removing the first file
from the {RD} list doesn't solve the problem. The debugger doesn't help at
all, showing a stop at this line in the macro:
Set oDoc = Documents.Open(FileName:=strCode)
If I remove all the RD coding, and start over, it all works again, until the
next day, when the whole error cycle begins again.
Whats going on and how do I fix it? Tag: i, Tag: 112354
Probleam with page numbering
Hi again all.
I have hit a bit of a wall here and need some help please.
I am writing a multi chapter manual. The layout of the document dictates
that the first chapter is Chapter 0 and it then continues normally from
there. That part is fine. Where I am running into problems is inserting the
chapter number then page number into the header. The TOC must have section
then page number (eg: 0-1......3-23 etc). The prog is not letting me change
the chapter # for the first chapter (in the header). It will not let me
select 0 but starts from 1. Is there any way to sort that out without having
to renumber the chapters to start with 1?
Thanks in advance.
Dominic Tag: i, Tag: 112351
Path for utilities
We've added commands to our Word menus to let the writers open our (HTML)
style guide and the MW dictionary. I path the style guide to a location on
our LAN. The dictionary commands are created on installing the MW dictionary,
but I control the command and toolbar button locations in our menus and
toolbars.
Now I'm sending my global add-ins to remote offices. The remote writers
don't have access to our servers (or LAN) and they may have a different
dictionary installed.
I'm thinking it would be better to code my VBA to use a Word path, like
those available on Tools > Options > File Locations. Maybe
Options.DefaultFilePath(wdToolsPath). The users could arrange to put a copy
of the style guide in that path, and a shortcut or copy of the dictionary EXE
in that path.
What do you think? Is this a reasonable strategy? Is there a better path to
use?
Bear
--
Windows XP, Word 2000 Tag: i, Tag: 112343
Vertical Scroll bar not operable in a Word form
Hi,
I have a simple User Form in Word that is sent to multiple users to collect
information. Due to the display resolution settings, some of the users are
able to see the form in its entirety they are unable to see the bottom
portion of the form.
I went to the form's property after opening the form in VBA mode and set the
"Scrollbars" property to "2 - frmscrollbarsvertical." This shows the
vertical scroll on the right side of the screen, but I am unable to use it
and move up and down on the form (there is no scroll drag in that scroll
screen). What am I doing wrong? / How can I correct this behavior? Thank
you for your time. Tag: i, Tag: 112341
need code to get entire paragraph containing selected text
Working on an Excel macro that needs to get some info out of a Word doc.
Need a bit of code to open the doc, search for an occurrence of a text string
(will only occur once) then assign the entire record (paragraph) containing
that string to a string variable. The name of the file to be opened is
already known.
Thanks for any help. Tag: i, Tag: 112338
Updating Multiple Documents in a Folder
I have several hundred Word documents in a network folder
(G:\Marketing\Updates) that I need to update with the same information. I've
created a procedure to do this to one document at a time, but I could save a
ton of time by having it automatically open each document in that folder, run
the procedure, save it, close it, then open the next one, etc.
Could someone help me with the code I need to do this? Thanks!
--
Steve C Tag: i, Tag: 112334
Range and Tables
Hi. I use this:
Public AllTags As New Collection
Public AllPoss As New Collection
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "\[\[|\]\]|\["
.IgnoreCase = True
.Global = True
End With
Set Matches = RegularExpressionObject.Execute(doc.Range.Text)
For Each Match In Matches
AllTags.Add (Match.Value)
AllPoss.Add (Match.FirstIndex)
Next
In other function when I want to delete some range:
Dim rang As Range
Set rang = doc.Range
rang.SetRange AllPoss(k - 1), AllPoss(k)
rang.Delete
It is ok but if I have tables in word document the range is other.
Example: If original postion is 30, This code Match.FirstIndex return 32
when position 30 is in Table. If we have not table Match.FirstIndex return
30. If wi have table original postion is 30 but Match.FirstIndex return 32.
Pleace help me. How I can get original postion in table? Tag: i, Tag: 112333
Why Close when you can Kill?
Hi
Can somebody please give me a good reason why Close function of certain
things like forms or word application obejcts should be used rather than just
killing them of as a process?
The thing is Im working with word objects and it is just such a pain because
when ever PC slows down you start getting errors like: Call was rejected by
callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
But if you close (for example) word app with process killer it works just
fine (no questions, no problems etc... :))
--
Government sucks, but the beer is still good! Tag: i, Tag: 112327
Error &H80004005
Using Windows XP, EXCEL Office 2003.
Each time I open an EXCEL workbook, I get the MICROSOFT VISUAL BASIC system
error '&H80004005 (-2147467259) unspecified error' message. I click on OK
about 17 times and then get another error message 'Compile error in hidden
module: This Workbook'. This happens each time I open an EXCEL file whether
it is a new one or not. Can anyone help me get rid of this, please?
Thanks
Yendorian Tag: i, Tag: 112326
issue with filedialog browser
Hi,
I have a question. I've a userform that has a textfield. Next to it, there
is a button with caption "Browse". I was thinking that when user wants to
insert a picture, he/she clicks on "browse" that will bring up a filedialog
box for user to select which image file they want to insert to the document.
Once, they have chosen the file, the filepath will be captured and shown in
the textfield that is next to it. After user has filled out all the text
fields in the userform and press "ok" button, all the user data will be
dumped to the word document. I use bookmark to do this.
So, getting back to my question. i have a bookmark in the word document. I
was hoping, the image will be placed where the bookmark for the image is in
the word document.
I use the following code to bring up the filedialog but couldn't retrieve
the filepath to the textfield. Instead, it actually opens up the file.
Dialogs(wdDialogFileOpen).Show
I have tried to use the following codes
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)
but got error message saying "invalid property".
I have done this before in excel but the codes below doesn't work well with
word.
filein = Application.GetOpenFilename()
Your help would be greatly appreciated.
Thank you in advance Tag: i, Tag: 112318
[Help]How to adjust Embedded Excel sheet 's view range
the detail info, please follow this link:
http://msdn.microsoft.com/newsgroups/default.aspx?&query=bluecoast&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.excel.programming&p=1&tid=27a75cb0-49f5-4d0c-8072-ca7f4453558b
--
From China Tag: i, Tag: 112316
issue with opening a file
Hi,
I have a question i need to ask of you MVP experts. Say, i have a several
customised templates dot files e.g. our company Letter template, Fax
template, and so on. Each of these templates have a userform (macro -
autonew) that would be called up as soon as a user opens up the template
My question is if i have a customised toolbar that has buttons for each of
these templates in the normal.dot. So when user opens up a word document,
he/she will find the toolbar. On the dropdown list, there are "Company
Letter", "Company Fax", "Company Report". When they click on Company Letter,
it brings up the Letter doc with the userform pops up waiting for user
inputs. That's the idea.
Today, i tried to do that but it actually opens up the template Letter.dot.
Hence, there is no userform showing up. This is not what i anticipated.
Here is my code for testing purpose only
Sub Macro1()
Documents.Open FileName:="C:\Documents and Settings\myComp\Application
Data\Microsoft\Templates\Company Letter.dot", ReadOnly:=True
End Sub
I might have used the wrong code here for opening a file.
Your ideas would be greatly appreciated.
Thank you in advance Tag: i, Tag: 112310
Excel (VBA) 2007 workbook in 2003 - available resources??
I have created from scratch a new main workbook and several 'satellite'
dynamically populated/'built' report templates - in 2007 (as, 2003 to 2007
seemed to fraught with danger).
All runs well, I have saved versions of the 2007 workbooks as 97-2003
workbooks with a couple of compatability 'fixes' around colour formats and
shape formats. In 2003, I can run these (both the master workbook and the
report templates )independantly and all works fine.
But - if I call the report via the parameter selection main workbook
reporting FORM - the report is found, opened, parameters populated, list
boxes filled and report dynamically structured - all well. THe code then
seeks to return to the main workbook to wrap up there - - and, alas, XL
either falls over OR I get the following message (ad-infinitum):
"Excel cannot complete this task with available resources. Choose less data
or close other applications."
Note - if the report is already open - and NOT opened via the procedure -
then, all is fine again - however, that's not really sustainable - to open
all report templates first...but - even though there ARE not links, is there
some silly order of opening issue here?
----any ideas??
There ARE pictures and shapes and activeX combo boxes on the report template.
The main workbook has pictures, shapes (acting as buttons), forms galore.
I've already found that using a 'shape' in 2007 to close a workbook is
dangerous and use activeX controls for that. I'm just a tad nervous about
this whole 2003/2007 thing. Tag: i, Tag: 112309
How to replace with a new template to a document
Here is my code:
Set thisDoc = Application.ActiveDocument
Set myTemp = thisDoc.AttachedTemplate
If myTemp.Path <> "C:\MyWordTemplate" Then
With thisDoc
.AttachedTemplate = "C:\MyWordTemplate\TestTemplate.dot"
.Save
End With
End If
I received the following message:
Word cannot attach a document to a protected template.
Thank you for any help. Tag: i, Tag: 112301
normal.dot locked?
I'm using Word 2003. I have a document created, for which I created a macro
that I saved. It runs fine. When I try to go to Tools | Macros and select
the new macro and click Edit, it tells me "Project is Unviewable". If I go
to Tools | Macros | Visual Basic Editor and right-click on "Normal" and
select properties, it tells me the same thing.
Additional info - I had wanted to eliminate the warning I got about embedded
macros, so I used Digital Signing, creating my own digital signature using
"Digital Signature for VBA Projects". Note that with respect to Digital
Signing, VBA macros within word, I know just enough to get myself into
serious trouble, and not much more. Anyway, I suspect I've dug myself a
hole, and I'm trying to figure out how to get out. How do I fix my
Normal.dot, and how do I fix things up so I can go back and edit this macro
that I created? Any ideas? Tag: i, Tag: 112300
Word 2007 ribbon
I am using the custom user interface editor to add a custom ribbon to a Word
2007 template. Is it possible to have the label on a button wrap to 2 lines?
I want it to look like this:
General
Instructions
NOT
General Instructions Tag: i, Tag: 112299
Searching for words in word document
I am c programmer who needs help with an idea. I have a lot of programs and I
place them in a word document to add notes not relevent to coding. After I
save them how can I search the documents for a particular word quickly. Sort
of like find.. next. Any help is greatly appreciated. Thanks.
-Carl Tag: i, Tag: 112298
ending multiple if/with statements
I have what I know has to be a very basic programming question. But I always
have trouble with this and have not been able to locate an answer that has
made it clear to me.
When you have multiple if and with statements: what is the proper sequence
to end them.
for example
if
with
with
if
I need to end the two "with" statements and the last "if", but not the first
one just yet. what is the proper sequence to end them?
end with
end with
end if
OR
end if
end with
end with
If someone could explain how to know what the sequence should be, I would
greatly appreaciate it. Thanks. Tag: i, Tag: 112296
Inserting Checkboxes into a table as an InlineShape using VBA coed
I wish to insert two checkboxes, side by side on the same line, in the third
column of a three column table. The Caption for one checkbox should be
"YES" and the other one should be "NO". I can insert one checkbox, but when
the code runs for the second checkbox, the first box gets overwritten. How
do I place the second checkbox next to the first checkbox on the same line?
I also want a small space between the two, say three spaces. Here is my
code. Thank you.
Sub insertInlineShapesCheckbox()
Dim myCheckbox1, myCheckbox2
'shifts insertion point to first tab
Selection.TypeText Text:=vbTab
'insert first checkbox
Set myCheckbox1 = Selection.InlineShapes.AddOLEControl(ClassType:="Forms.
CheckBox.1")
With myCheckbox1.OLEFormat.Object
.TextAlign = 3
.Alignment = 0
.Width = 43
.Caption = "YES"
.FontName = "Arial"
.FontSize = 11
End With
'Selection.TypeText Text:=" "
'Selection.TypeText Text:=vbTab
'insert second checkbox
Set myCheckbox2 = Selection.InlineShapes.AddOLEControl(ClassType:="Forms.
CheckBox.1")
With myCheckbox2.OLEFormat.Object
.TextAlign = 3
.Alignment = 0
.Width = 43
.Caption = "NO"
.FontName = "Arial"
.FontSize = 11
End With
End Sub
url:http://www.ureader.com/gp/1022-1.aspx Tag: i, Tag: 112291
Can't read Range.Text in a protected document
I need to find all emails inside a Word document. The problem is that when
the document is protected, I can't read the Text property of the range. I get
an error saying that the document is protected (Error #4605). All I'm doing
is reading, I'm not modifying anything. I use the Split function to get the
sentence of words where the @ sign was found, then I loop through the
elements of my array until I get to the one that has the @ sign. It's this
line that causes the error.
Here part of my code:
For Each rngStory In objDocument.StoryRanges
With rngStory.Find
.ClearFormatting
.Text = "@"
.Wrap = wdFindStop
.Forward = True
End With
Do Until rngStory.Find.Execute = False
With rngStory.Duplicate
.Expand Unit:=wdSentence
myArray = Split(.Text, " ", -1, vbTextCompare) '///
Error here !!!
If UBound(myArray) <> -1 Then
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "@", vbTextCompare) <> 0
Then
'/// ... Process Email here
numEmailsFound = numEmailsFound + 1
End If
Next i
End If
End With
Loop
Next rngStory Tag: i, Tag: 112289
Search within a range
I have defined a range. Now I need to be able to search for a specific
phrase, move to the end of that phrase, insert a carriage return and insert a
new phrase. This is what I was trying, but it is not working. I don't get
any errors. It just doesn't work. I'm pretty sure it has something to do
with meNotice vs. selection. But I just can't quite figure out the syntax.
Any help would be greatly appreciated.
Set meNotice = .Sections(.Sections.Count).Range
With meNotice.Find
.Text = "time shown below."
If .Execute Then
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.InsertAfter Chr$(13) & "PLEASE TELEPHONE ME IMMEDIATELY."
End If
End With Tag: i, Tag: 112288
turn off automatic date completion
When I write a word in my Microsoft words 2007 editor that indicates the
beginning of date some automatic completion mechanism is triggered displaying
the full date.
Unfortunately in my native language (Swedish) there are some words that are
very common but that also could be the beginning of a date so this flashing
occurs very often.
I do not like this so I wonder how a script could look to disable this
mechanism? Tag: i, Tag: 112287
Make a copy of a Word VBA programme saved in the template directory
Hi,
I have written a complicated Word VBA programme and saved it as a
template. May I ask how I can make a copy of it so that I can move
the copy to another computer and use it there? Thanks.
Mike Tag: i, Tag: 112285
Spellchecking a Protected Document
This seems to be a popular topic lately, so I thought I'd chime in as well.
While the article at
http://word.mvps.org/faqs/macrosvba/SpellcheckProtectDoc.htm is great if you
want to check the spelling of the information input into formfields, my
problem is a bit different. I have (Word 2003) templates that produce
forms-protected documents, but the documents themselves don't contain any
formfields. I use forms protection only because it allows me to protect only
certain sections of the document, such as the header and footer, while
leaving other sections, such as the main body of the document unprotected.
The spellchecker checks the spelling in the unprotected sections OK, and I
don't really mind if it doesn't check the spelling in the protected sections
because 1) I know that I haven't made any spelling errors in the
'boilerplate' in these sections; and 2) if the user has made a spelling error
in the 'variable' information, they can just rerun the code in template to
correct the errors. However, there is a deficiency in the native spellchecker
that I've been asked to develop a workaround for.
In an unprotected document, if none of the choices in the 'Suggestions' list
are viable, you can just type in the 'Not in Dictionary' box to make the
change. However, this doesn't work in a protected document; the text in the
'Not in Dictionary' box is treated like it's in a protected section. I could
always write code that unprotects the document before displaying the
spellchecker, but there are a couple of drawbacks:
First, this will allow the users to spellcheck the protected sections as
well, which is not really a major problem except that if the user corrects an
error that was introduced through the input of the 'variable' information
described above, this correction won't get replicated back into the data from
the UserForm. Thus if the user reruns the template, the correction won't be
there and the error could be reintroduced without the user realising it.
However, I can live with this.
The real problem is that the spellchecker dialog isn't modal to Word.
Therefore, if I unprotect the document, the user now has full access to the
whole document, _including_ the protected sections. And believe me, the users
will take advantage of this whenever possible; I learned this when I told the
users I was going to fix a bug in my code that left the document unprotected
and got a... umm... less than favourable response. ;-D
Does anyone know a way to enable the editing capability in the 'Not in
Dictionary' box without unprotecting the document? Or will my users just have
to live with this limitation? (The second choice is acceptable as I'm quite
happy to tell the users 'No' - as long as I can justify the response.)
--
Cheers!
The Kiwi Koder
Please note: Uninvited email contact will be marked as SPAM and ignored -
unless you want to hire me. Tag: i, Tag: 112277
Sharing Arrays Between Modules
In an earlier post, Jean-Guy Marcil provided me with some excellent
instruction on structuring projects to separate UserForm-related processes
from document-related processes. (Thanks again, Jean-Guy!) I'm now trying to
apply this structure to a somewhat more complex project and have run into a
problem straight away.
In this new project, I use arrays to collect sets of similar information
(e.g. the names and addresses of multiple parties to a contract). These
arrays all reside in the UserForm class module, since they are obviously
integral to the processes related to the UserForm; i.e. UserForm operations
are used to create and maintain the arrays, and the arrays are used to
display information in the UserForm.
However, I cannot find a way to take the information in these arrays and
transfer it back into the 'operational' class module that is used to perform
the actual document-creation processes. UserForm controls (and the values
contained therein) are simple enough to access and variables can be declared
as Public and then just become a 'pseudo-attribute' of the UserForm object,
but arrays cannot be Public.
For obvious reasons, I don't want to dynamically create a heap of Public
variables to dump the contents of the arrays into and then rebuild the arrays
on the 'operational' side, and doing something like grabbing the contents of
the ListBoxes that are used to display and maintain the arrays on the
UserForm and then attempting to parse this information scares the daylights
out of me. Does anybody have any suggestions on how to share contents of an
array between two modules?
--
Cheers!
The Kiwi Koder
Please note: Uninvited email contact will be marked as SPAM and ignored -
unless you want to hire me. ;-) Tag: i, Tag: 112273
Help with MVP spellcheck protected form code
I am trying to use the code from
http://word.mvps.org/faqs/macrosvba/SpellcheckProtectDoc.htm
and I got an error that the password was incorrect so I tried to follow the
directions from the website but I am still unsure where to insert
oDoc.Unprotect Password:="colleen"
And:
oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:="colleen"
in to the code in the right places to get it to work. Help anybody? Thanks!
~Roxy Tag: i, Tag: 112271
Fetching data in Excel from Word
Hello,
I have a Word document.
I have in an Excel file with thousands of IP adresses and other similar type
of information.
In the word document, I have to create a chapter for each physical servers
(a lot).
In each chapter, a table display the IP configuration of the sever as well
as virtualized servers inside it (a lot more)
These information are randomy defined in the Excel file.
What is the best way to do that ?
I'd like to have a button in the word document which call a macro.
This macro would open the Excel document and lookup the IP information based
on the server name.
Then, it would update tags or fields or variables that I would insert here
and there in the word document.
The goal here is to avoid regrouping & copying by hand thousands of IP
adresses, which is prone to mistakes.
Moreover, whenever the IP adresses are updated in the Excel file, I would
run the macro to update the word document.
Any good idea ?
I know how to do a macro in Excel, but never did one in word.
My main problem is how to create a "field" or a "variable" in the text
(generally in -but not restricted to- a table) that my macro would recognise
in the word document and update it ?
Thanks in advance.
JD Tag: i, Tag: 112266
project locked
Hi,
Sorry if this has been asked recently or frequently.
Somehow all my projects are looked. If I download a dot-file, add it
and then try to open the macros in the editor, they are all locked.
Even if I myself create a dot-file, add a project, type some dummy
macrotext, close and then add that dot-file to another document, also
that project is locked. I can´t even open the properties.
The security settings are on the lowest level. Word 2003
What do I do wrong?
TIA
Örjan Tag: i, Tag: 112265
Passing Values to a Module
I created a form in VB called DemogInfoForm and would like to know how I can
pass the value entered from a text box to a module? The instructions are on
the "command OK" button. The value will also be used to gather other
information from the mainframe. Here is what I got so far...
Sub OkButton_Click()
On Error GoTo Err_Command
Me.CaSEText.SetFocus
If Len(Me.CaSEText.Text) <> 10 Then 'Message that wrong number
of digits entered for case number MsgBox "Please enter the 10-digit Case
Number." _ & vbCrLf _ & " Please try again!", vbCritical, "10-digit Number
Error Message"
Exit Sub
Else
'Once the value is verified, I would like to pass the value to the
CaseNUMFind module .... thank you
CaseNUMFind (Number) 'Go to module Tag: i, Tag: 112264
Word 2003 custom Menus change and disappear
Does anyone have a fool proof method for stabilizing custom menus (on the
menu bar) in Word?
I have a menu in a global template that should always show, as well as
document templates that each contain a menu I want to appear only when
someone is in a document created from that template.
The problem SEEMS to stem from OTHER people's software -- the menus will be
there but then they disappear, or multiple copies appear or the menu is
suddenly empty or has the name for one menu with choices for another menu on
it.
Note: Custom TOOLBARS seem stable, it is just the MENU that is problematic.
I have been fighting this for years and have done a lot of research but so
far everything I try has a hiccup at some point. The programming is all VBA
in Word .dot templates.
So far I have tried:
- Using tools, customize to create the menus w/in the appropriate templates
-- works great on my computer, but menus disappear/duplicate constantly on
about 80% of my clients.
- Programmatically creating the menus -- this is good for the global
template menu -- at first -- but somewhere through the day it gets trashed.
I can't get the template specific menus to behave. They constantly disappear.
- Write an event handler to delete and then recreate all menus and display
as (Tried with the "Document change" or "WIndow Activate" event for the Word
application) -- this seemed to work at first but suddenly the problems
returned. I did not want to just "show" the menus per the event handler
because they would suddenly have the wrong buttons or be empty part way
through the day. (Maybe I am not writing it right.)
Has anyone else had this struggle? It happens to me so much I am surprised
I can't find more postings about it. PLEASE HELP!!!!! Thanks so much. Tag: i, Tag: 112256
OrganizerCopy Error Dialog Problem
When using OrganizerCopy, if the style name is not found in the source
document, Word returns an error dialog. In a VBA application, is there anyway
to suppress this dialog and let the code continue without the user having to
click OK?
The sample code. The dialog after the gSourceWordApp.OrganizerCopy call but
before the If Err.Number = 4198 Then line.
On Error Resume Next
Dim styleName As String
styleName = "corporateNameStyle"
gSourceWordApp.OrganizerCopy Source:=sourceDocument.FindInFileName, _
Destination:=indexWordDocument.FullName, _
Name:=styleName, _
object:=wdOrganizerObjectStyles
If Err.Number = 4198 Then
gSourceWordApp.OrganizerCopy Source:=sourceDocument.FindInFileName, _
Destination:=indexWordDocument.FullName, _
Name:="Normal", _
object:=wdOrganizerObjectStyles
End If Tag: i, Tag: 112253
Comparing Word documents
I inherited some Word VBA code to format a report based on rtf output
from DOORS. I made some changes to the VBA to improve performance (it
used to run for more than hour) and now I would like to compare the
Word document produced from the latest version with a Word document
produced from the previous version of the Word VBA macros.
I am running Microsoft Office Word 2003. I opened the more recent
copy, and then:
1. pulled down Tools-->Compare and Merge documents...
2. checked the "Legal Blackline" checkbox
3. selected the baseline word document produced under the old macro
set
4. clicked on "Compare"
The only differences that showed up was that every row of the main
table is black-barred with (on each page) a change box pointing at the
header saying "Formatted Table".
When I move my mouse over the "Formatted Table" change box it says
"Author formatted Table:"
Any clue what this is trying to tell me? The contents look fine
otherwise.
--Thank you,
--Mike Jr. Tag: i, Tag: 112251
Spaces after 1 incorporate footnote
Below is my 1 space after macro, but I need to add 1 space after footnote -
I keep getting errors in my attempts:
.^f<space><space>
to be .^f<space>
a single space after footnote is that possible to do?
Sub Spaces_After()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([.\?\!]) {1,}"
.Replacement.Text = "\1 "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " ^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWholeWord = False
.MatchWildcards = False
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.HomeKey Unit:=wdStory
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute
Wend
Selection.Find.Text = " ^l"
Selection.Find.Replacement.Text = "^l"
Selection.Find.Execute
While Selection.Find.Found
Selection.HomeKey Unit:=wdStory
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute
Wend
End Sub Tag: i, Tag: 112250
VBA Code cleaners
Does anyone know where I can get a VBA Code Cleaner program which
works with Word 2003 and above, please?
All the ones I've found seem to concentrate on Excel but not Word.
I've always used the one mentioned in the MVPS site but this only
works up to Word 2002.
Thanks
Roderick Tag: i, Tag: 112249
Changing the default spelling language for Word 2007
Hello,
Is it possible to change the default office (word) spelling language from
code?
Preferably from c#,
I have not found the location where word stores this.
Kind regards,
Sven Maes Tag: i, Tag: 112240
if bookmark.Exist (Left("nut", 3)
Hi all
I am hoping to use VBA to check if a document has a bookmark starting with a
particular string. I thought I could use LEFT to check if it exists but it
does not pick up the bookmark.
Checking if bookmark exits works perfectly when not using LEFT
Ive tried:
If ActiveDocument.Bookmarks.Exists(Left("_BD", 3)) = True Then
msgbox "Yes its here"
end if
I found that looping through the document works but I do want to search for
each bookmark eg:
Dim myBM As Bookmark
For Each myBM In ActiveDocument.Bookmarks
If ActiveDocument.Bookmarks.Exists(myBM.Name) And Left(myBM.Name, 3) =
"_BD" then
do this
End If
Next myBM
Any ideas?
Thanks in advance Tag: i, Tag: 112237
MACRO TO TOGGLE FONT ON AND OFF
I have document that uses a particular font (usually no more than a few
characters in length) in numerous places throughout. Is there a macro that
would toggle this font on and off using a shortcut-key combination (e.g.
like the way that CTRL + "I" does for italic type)?
--
JBusby Tag: i, Tag: 112236
Wrong font color for envelopes
When I try to use the tab for letters and labels when printing an envelope,
the type comes out green even though black is the default color. It does not
happen with labels. Tag: i, Tag: 112234
Programing the page number
Hello:
I have an application of Visual Basic 2005. I can make a word XP document
("Document 1") by code inside the application. I want to put the page number
in the document but I don't know how from inside the code of Visual Basic.
That's the problem.
Thanks Tag: i, Tag: 112231
printing macro
built a macro in word to bring data from an excel worksheet. Is there
a way to have word merge stop at a location instead of searching the
full excel sheet. Have used first & last 1 & 50 still goes the
limit.This is being done in 2000 as the people who will use after I am
gone are novices as I am. This is really my last hurdle to this
project.
Thanks to anyone who can speed up this merge. Tag: i, Tag: 112228
Setting a Range
Can someone tell me how to set a range for the last section of a document?
Or as an alternative how to set the range to the section where the cursor is?
Specifically what I need to do is set the last section as a range so I can
make some modifications. First I need to delete the last two rows from a
table in that section (there are two tables, and I need to delete rows 3 and
4 from the second table). Then I need to search for a text string, and
insert some text in front of the original text.
Thanks for any help. Tag: i, Tag: 112222
Change font Colour/Color
I have a template document on which I want to be able to change lightblue to
black after drafting the document.
I have the following code in my macro at the moment and it works ok I just
wondered if there was a more efficient way of writing it that I haven't
thought of or if I should do some error checking on it as well.
Still finding my way around vba at the moment and am improving with the help
of this site.
Public Sub SetTextToBlack()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Font.Color = wdColorLightBlue
.Replacement.Font.Color = wdColorBlack
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
Selection.MoveRight
End Sub
Many thanks
JayM Tag: i, Tag: 112220
Deleting text boxes with red line or text
Is it possible to use VBA to delete text boxes in a word document that
have a red line around them (or with red text in)?
If so can you point me in the right direction for the code
Many thanks
JayM Tag: i, Tag: 112217
PLEASE respond ASAP
Hi there,
It's a crazy problem i'm facing. I have to work on many documents and there
will be a footer kind of note, same note I have to keep in each document but
the page is not the same. For example, there is a word "xyz" and we dont know
in the document where it comes, when it appears there should be a footnote in
the first instance of the document. If it comes in the second page of one
document, it comes on someother page in other document. SO I thought of
recording a macro as the text is same for all. Now it is working, when I say
run it appears BUT IN ALL PAGES OF THE DOCUMENT whereas I require only in the
active page, that is the page where I am working and is needed. I mean, when
I go to a particular page and run the macro, it should come only on that
particular page and not the entire document.
How can I edit the code to do that? Where and what should add inside the
coding to write the text in particular page. Otherwise, everytime I have to
either open or keep open the other document, copy and paste. I thought of a
simple macro but it is becoming complicated.
Sorry for a big explanation, I just want to make clear.
Thanks in advance for your valuable time and solutions. But please respond
asap. Tag: i, Tag: 112214
Combo Box
Is there a way in Word VBA to create a combo or list box where values can be
displayed and also have the ability to add and delete items. For instance
have a list of predefined food that the user can modify via the list and add
additional items or remove items of food they don't want on the list?
Thanks in advance Tag: i, Tag: 112209
VBA to determine Word version of a document
Hi,
I need to create a vba macro that will provide info about which version
(fileformat) of Word the active document was saved in.
I tried the following, but no luck:
Sub CheckDocType()
'Assuming that constants are as follows: Format 15 - docx; Format 16 - docm
If ActiveDocument.SaveFormat = 15 Or ActiveDocument.SaveFormat = 16 Then
MsgBox "This document is a Word 2007."
End If
End Sub
Thanks Tag: i, Tag: 112208
macro to toggle Autotext Menu on & off
Seems like it should go something like this - but it doesn't work:
Sub ViewAutotextMenu()
IF CommandBars("AutoText").Visible = True
Then CommandBars("AutoText").Visible = False
End If
if CommandBars("AutoText").Visible = False
Then CommandBars("AutoText").Visible = True
End If
End Sub Tag: i, Tag: 112207
There is the control (RichTextBox) for VBA?
Hello. I want to insert into form (Word VBA) textbox but it have not
context menu. There is any other controls (e.g. RichTextBox) for VBA?
Or not?
Thank you. Tag: i, Tag: 112202