showing only some parts of a document
I´m not sure how to explain my problem. I´m making a contract with different
paragraphs and parts in it. It is a general contract but it would be used to
many purposes. I would like it to be so that you can choose in the beginning
wich parts and paragraphs of the contract you want to use and it the document
would be automatically biuilt according to those wishes. Is this possible and
if it is, how? Tag: document template Tag: 113338
How to make it search from the beginning of the document?
Hi,
Somebody gave me the following code to search words in red in a
document:
With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Color = wdColorRed
End With
While Selection.Find.Execute
MsgBox (Selection.Text)
Wend
May I know how to force it to seach from the beginning of a document?
Thanks.
Mike Tag: document template Tag: 113336
Force Saving Document with New Name
I am opening a document with
Set DocB = Word.Documents.Open(DocA.Path & "\Intro.doc")
I would like the file to show as "Document1" (or whatever the next new
document would be) so that the user is forced to save it with a new
name.
Is this possible?
thanks,
dave Tag: document template Tag: 113332
macro for displaying section field +1 digit?
The Section field, when added into a document, displays an arabic numeral
showing the section number where it resides.
What syntax would cause display of the section number, incremented by one
digit?
(ie, the Section field, if placed in section 2, displays a "2" but with this
new syntax, would display a "3"; if positioned in section 12 it would
display a "13", etc.) Tag: document template Tag: 113327
"Probable VIRUS Detected" message
I create a very short macro for a particular form document and get this
message whenever I open the document. It is a very simple macro that turns
off the document protection when the user reaches the last Text form field.
How do I stop this from appearing? Tag: document template Tag: 113326
removong 'blank' pages
hi, I have code that produces various documents.
Now, in the main, the documents are printed on a duplex printer and so
the document contains extra page breaks to ensure that certain pages
dont print on the reverse of the previous page (ie it inserts 2 page
breaks instead of 1)
However, sometimes i'll be printing on a single sided printer and as
such i end up getting a load of 'blank' pages (apart from the header
and footer).
Is tehre a way i can loop thru all pages in the doc and if there is
nothing in the main body of a page then it removes the page?
Thanks. Tag: document template Tag: 113318
Hiding open document
Hi, is it possible to write code that hides the open word document
from view (but doesn't actually close it) and vice versa.
I know you can hide workbooks in excel, but i cant see that you can do
the same in Word so cant even begin to try and code it.
Cheers. Tag: document template Tag: 113317
Removing text boxes while preserving the text inside them
There are several macros around to remove text boxes from a document,
but I cannot find a way to preserve the text inside them.
Can anybody point me to one which actually works?
Thanks a lot
--
John Doue Tag: document template Tag: 113307
Adding multiple files
I have a template which has the ability to add additional files that has form
fields which I update from a query (driver info). What users would like is
the ability to add this same file (document) multiple times and have it
updated accordingly. I figured I could add a textbox to the template for
users to input the driver numbers and add according to this.
Let's say the insertable document has 5 form fields, text1 - text5.
ActiveDocument.FormFields("Text1").Result = strDriver
ActiveDocument.FormFields("Text2").Result = strVehicle
etc.
My question is this:
How can I add this same document multiple times and have my query update the
one just added ?
Assume I added form for driver 1 and updated fields, and now I add for
driver 2, how can I update the second form added with driver 2 info when the
form fields are the same ?
Or is my only solution to have the same document saved multiple times (ie
Driver1.doc, Driver2.doc, etc) with the form fields named different in each?
Thanks,
Bryan Tag: document template Tag: 113299
SEQ field and grouped textboxes not working right.
I'm editing a document with quite a few embedded images and captions in Word
2003. For ease of use, I've been grouping the floating images and the
captions so they don't get separated as text gets added. However, when I
group two different images and the associated captions, the SEQ field in the
caption starts acting wonky. It'll number them properly throughout the
document, but the two text boxes that contain the SEQ fields will have the
same value for them.
For example:
Group: Image 1 & Caption 1. SEQ displays 1.
Group: Image 2 & Caption 2. SEQ displays 2.
Group: Image 3, Image 4, Caption 3 & Caption 4. SEQ for both captions
displays 4.
Group: Image 5, Image 6, Image 7, Caption 5, Caption 6 & Caption 7. SEQ for
all captions displays 7.
Group: Image 8 & Caption 8. SEQ displays 8.
Is there a way around whatever is causing this issue? Tag: document template Tag: 113298
change the style formatting on the new word doc
Hi,
I have a question in regards to autotexts for word 03.
I have an autotexts that has contents of style "Section Heading 1" in it.
Then, i have a template that has macro to call that autotexts. In the
template, i have also set up a style "Section Heading 1". After running the
template, a new word document is produced with that autotext. I noticed that
there were two styles in that word document, one is "Section Heading 1" and
the other one is "Section Heading 1 + Justified". I don't know how to keep
this two the same as just "Section Heading 1". This is my intention but i
guess word works differently.
The trouble here is that we're talking about two different style when there
should be only one style sheet formatting namely "Section Heading 1".
My question is how can i change those content from the autotexts whose
style's "Section Heading 1 + Justified" to just "Section Heading 1" onn the
new created word document?
Thank you in advance Tag: document template Tag: 113282
Resetting Window back to Word at end of Macro
Hi there -
I have two issues I would like to resolve for this macro:
1) I would like to reset the Window back to Word (from Outlook) after the
macro runs. It currently stays in Outlook after it is run. This would be
confusing to the user.
2)I would like to know if I can make the .CC property a variable that can
always retrieve and copy the current user email address in the cc field of
the email.
Below is the the code I am using:
Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved prior to running this step. Use MS
Word Menu: File->Save As."
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "somebody@mail.com"
'Set the recipient for a copy
.CC = "currentuseremail@mail.com"
.Subject = "New Document"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="New Document.doc"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub Tag: document template Tag: 113278
Macro for Auto Table of Contents
Any ideas on a macro that will automatically build a table of contents? I am
trying to avoid having to manually tag each page. Is there a way I can tag
the a certain part of each page, which will be updated when pages are added
to the document. Let me know if I'm not being clear. Any help is appreciated. Tag: document template Tag: 113273
Adding different style text to the same range
Hi all,
I'm trying to create a new document, add a range, then add heading 1
text followed by normal text for each of several sections I'm trying
to insert.
The code for the insertion of the headers is as follows:
Set listDoc = Documents.Add
sourceDoc.Activate
Dim o As Range
For Each i In colStyles
listDoc.Range.InsertAfter CStr(i) & vbCr
listDoc.Range.Style = "Heading 1"
ExtractByStyle CStr(i), listDoc.Range
Next i
The ExtractByStyle code is here:
Sub ExtractByStyle(sStyle As String, ByRef myRange As Range)
myRange.Collapse wdCollapseEnd
If StyleExists(sStyle) Then
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = sStyle
Do While Selection.Find.Execute(findText:="",
MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True)
myRange.InsertAfter Selection.Range & vbCr
Selection.Collapse wdCollapseEnd
Loop
Else
myRange.InsertAfter "Style " & sStyle & " doesn't exist!" & vbCr
End If
myRange.InsertAfter vbCr
myRange.Style = wdStyleNormal
End Sub
The first heading and all following text comes out as Heading 1; the
second heading seems to work. It is Heading 1, and subsequent text is
normal.
Help! Tag: document template Tag: 113271
Completely Copying Styles
How can I use vba to create new style, using an existing style as a model -
but NOT using "based on". In other words, I want to copy EVERYTHING possible
about a style into a new style, with a new name.
Does anybody have any idea how to do this completely, thoroughly, and
accurately?
(This applies to paragraph styles as well as character styles.)
I would greatly appreciate any help you can provide.
Thanks! :) Tag: document template Tag: 113270
inserting a file
I am using the following code to insert a file into a template which has
letterhead and footer.
"
Dim myDoc As Document
Dim docrange As Range
Set myDoc = ActiveDocument
With myDoc
.Unprotect
Set docrange = .Range
docrange.Collapse wdCollapseEnd
docrange.InsertBreak wdSectionBreakNextPage
Set docrange = .Range
docrange.Collapse wdCollapseEnd
docrange.InsertFile "W:MN Collective Bargaining Letter.doc"
.Protect wdAllowOnlyFormFields, NoReset
End With
The template has letterhead, so this code adds a section break with the
letterhead and footer (Company address, emial, etc).
What I want to do is just add a word file next page as it is (no letterhead
or footer).
I have tried different things , even manually, like insert > Break > Page
break and I don't get the header but, still get the footer.
Any thoughts..
Thanks,
Bryan Tag: document template Tag: 113265
Call to Excel from Word keeps active XL process
I have a VBA macro in Word that pulls a list of information from an Excel
spreadsheet. I'm using the following code:
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = False
.Workbooks.Open FileName:=strFileName
End With
Then at the end of my module:
xlApp.Quit
Set xlApp = Nothing
Problem is that Excel continues to run. I have to go into Task Manager and
end the process.
If there a way to have the Excel process programmatically? Tag: document template Tag: 113263
INSERTFILE fails when importing EXCEL worksheet using Word2003
can not use insert file to import EXCEL worksheet range using
Word2003 .
This post
http://groups.google.com/group/microsoft.public.word.vba.general/browse_thread/thread/3edf845d81957845/4d2aef2cb0a04e7f?lnk=st&q=InsertFile+word+range+excel+2003#4d2aef2cb0a04e7f
says to download oconvpck.exe from microsoft website, but after
install it i still i can't import it.
Some suggestions ?
Thanks Tag: document template Tag: 113259
to: Jay Freedman re: macro to get initials and go to bookmark
Many thanks for your help with my recent question. I'm hoping you
have time to answer one more:
you had said in your reply:
"Storing the names and addresses directly in the code this way is
acceptable if
there are only a few, and if they don't change very often. If that
isn't the
case, you don't want to have to edit the macro every time there's a
change. Then
you want to store the names and addresses somewhere else -- in a Word
document,
an Excel worksheet, a database, etc. -- and read that source when the
macro
runs. "
In the case of the macro I asked about, storing the code in the macro
should be fine...but for future reference, how would I store the names
& address in a Word document and have the macro 'call' that info?
thanks again!
Ruth Tag: document template Tag: 113258
Help: Need to send active document as attachment via Outlook
I need a macro that automatically sends the current active document via email
to one specific user. It sounds easy, but I have not found anything that
meets this exactly.
Options I have found include: MsoEnvelope Object and SendForReview Method.
They provide the following hurdles: MsoEnvelope does not send document as
attachment, only the document content as the body of the email.
SendForReview sends the document with the Tracking status ON, which I do NOT
want. Any help overcoming this or any other options to solve my issues would
be great. I will take anyway to send an attachment to a specified user.
I have tried using:
Sub SendMail
With Application.ActiveDocument.MailEnvelope
.Introduction = "Please read this and send me your comments."
'Return a Microsoft Outlook MailItem object that
'you can use to send the document.
With .Item
.Recipients.Add "somebody@misc.com"
.Subject = "Here is the document."
'The body of this message will be
'the content of the active document.
.Send
End Sub
OR
Sub WebReview()
ThisDocument.SendForReview _
Recipients:="someone@example.com; amy jones", _
Subject:="Please review this document.", _
ShowMessage:=False, _
IncludeAttachment:=True
End Sub Tag: document template Tag: 113249
Word. VC++6.0. How I can retrieve current number row?
Hello,
I have an application in VC++ 6.0. This application creates a .DOC file for
Word2007. In this file I insert text and image (.bmp)
This is my problem:
When I insert text and/or image how I can retrieve current row?
I need to get current number row. Someone can help me with sample code in
VC++?
Thanks Tag: document template Tag: 113248
macro help please
Hello all this is my first post. I could do with your advice.
I have a 20 similar documents which share many repeating comments of 1
sentence long. I have to update these old comments with new edited comments.
I have created a table with two columns, containing the old comments and the
corresponding new comments that I have edited. I plan to make a macro in
Msword to find and replace the old comments for new, then run the macro on
all 20 documents.
However the process of creating the macro in itself is likely to take
considerable time due to the number of comments (approx 250- 500 in total).
And hereâ??s the question: Is there a way to make the macro use the table to
change the old comments for the new? Or is there an easier way to do this?
Any help would be greatly appreciated. If you require any other
clarifications, please let me know, thanks in advance, Den. Tag: document template Tag: 113247
Problem deleting a paragraph
Hi All
I'm using the following vba to remove a bookmark and paragraph
WordDocOnlMemAcc.Bookmarks("Line1").Select
WordDocOnlMemAcc.Bookmarks("line1").Range.Paragraphs(1).Range.Delete
WordDocOnlMemAcc is the object representing the document in use.
If i run the code normally the bookmark is deleted, if i step through
the code the paragraph gets deleted as i wanted. Any ideas what the
problem/solution is?
cheers
Keith Tag: document template Tag: 113243
can i convert Flash file to PPT?
hi,
how will i edit the swf file's content in PPT?.
do you have any option for the editing the content?..
and i try to access the next slide for the particular button,do u have any
option for this?...
Thanks Tag: document template Tag: 113237
need macro to prompt user for initials & use if statement to plug in
Hi, I'm a former Wordperfect user.
this was easy to do in WP, but I need to do it in Word 2003.
Inside the letterhead template (probably using AutoNew?)
I need the macro to
1. prompt user for the attorney's initials
2. Then use an if statement to go to bookmarks and fill in fields
based on the initials.
For example, the user types in 'abc'.
the macro presumably would use some sort of 'if' statement: If
variable 'initials' equals 'abc'
then go bookmark 'name' and type 'Andrew B. Cooper.' then go to
bookmark 'email' and type 'abcooper@company.com'
However, if the user types in 'def', the macro would go to the 'name'
bookmark and type Donna E. Foxx and then go to the bookmark 'email'
and type 'defoxx@company.com'
Many thanks for any assistance! Tag: document template Tag: 113232
How to Reference to the IADs object
I want to connect to Active Directory and I need to use the IADs object.
What is the name of the reference for that
Thanks, Rich Tag: document template Tag: 113227
Building a WOrd Document
I have done all of my VBA programming from Excel. Now I haev a task in Word
and feel like a fish out of water!
Point me in the right direction(s), please.
I have a document which goes on for several pages. Let's call them "Rules
1-30" with each rule a paragraph or two. What I'd like to do is present a
dialog which prompts the user to select which rules/paragraphs to include,
and then present them a Word Document to save and print which has just the
rules they selected.
Of course there is much more involved but this would get me going. Any
links to examples is appreciated. Sites to visit,, etc.
-----
Of course I'd like to be able to prompt for names, dates, accounts first
then insert the selected rules, then some closing info. Tag: document template Tag: 113226
combo box, drop down - dynamic populate
I have an insurance template which auto populates some fields from a
database. One of the fields being populated is a client id. What I would also
like to do get the policies of this client and populate a drop down or combo
box.
I know how to sql the databases but unsure of how to populate the drop-down
or combo box for selection.
Example:
Let's say client abc has 5 different policies with our company (PAP 101, HO
123, CF 345, MC 456, and GL 890).
I would like the drop down or combo box to populate with this info.
Once one is selected then I would populate additional fileds based upon
info of that policy.
Thanks for the help in advance.
Bryan Tag: document template Tag: 113225
word07- auto fill isn't working - type febru and no suggestion.
Using Word 07 - in older programs when you type say, the month, it would pop
up and you could 'auto fill' by hitting enter. This is NOT working for some
reason. I've tried to correct in in Word Options. Could I have changed it
somehow in my Styles settings?
I would like this turned on for ALL Word documents. Please help!
Thank you.
--
Gardengramma Tag: document template Tag: 113223
Macro to remove a word in a specific heading level?
Hi,
I am hoping someone can help asnwer this question:
Let's say I have a word "XYZ" scattered throughout my Word document. That
Word document contains many heading levels, like:
1.
1.1
1.1.1
1.1.1.1
How do I write a macro that can remove "XYZ" only if it is in the 4th
heading level (e.g. 1.1.1.1, 1.1.1.2, 2.1.2.3, etc.)?
Also, how do I make it so the macro can also search for text blocks that
span multiple lines, like, for example,:
A
â?¢ B
C
â?¢ D
I want to be able to find and replace all text blocks that have exactly the
above format and everything, including the bullets.
Thanks. Tag: document template Tag: 113222
Macro to remove lines containing specific text
I would like to be able to remove all lines from a Word document which
contain a specific text string and copy them to a second file at the same
time.
Can someone suggest some code that could do that?
I have seen similar posts in this forum which are close to my needs but none
that show me the code needed to both remove the entire line and append it to
a new file.
Thanks in advance
Al Tag: document template Tag: 113221
Sending Emails in Groupwise 7
I have been using this code to send emails in Groupwise 6.5 with no problems.
With Groupwise 7, it fails at the .subject line with message
"Run Time error '91'
Object variable or with block variable not set
It does not like .subject, .addrecipient and yet it brings them up when you
type a period
docActive.SaveAs strTemp
docActive.HasRoutingSlip = True
With docActive.RoutingSlip
.Subject = "Gifts and Benefits Declaration from " & Me.txtAuthor
.AddRecipient strEmail(i)
.Delivery = wdAllAtOnce
End With
Any ideas please?
Stephen Tag: document template Tag: 113210
Hyperlink in a macro comment
I'm trying to set up macros to streamline grading essays, and I want to
include hyperlinks in comments that I have created as commands on a new menu.
I create each command as a macro that inserts a comment with text about the
error I've found, but I can't figure out how to include the hyperlink in the
text that is in the comment. When I record the macro, I can type in the URL
as part of the text in the comment, but it isn't hyperlinked. So, for
example, I've created a menu in Word called "Sentence Errors" and each
command inserts a comment regarding a particular type of error. Here is an
example fo the type of text I want to include in a comment:
You seem to be having some trouble shaping your sentences so that they read
clearly and smoothly. Try reading your words out loud. Often your ear can
help you determine if your writing is awkward. You should also visit
http://owl.english.purdue.edu/owl/resource/604/01 to review the various ways
in which sentences can be structured.
But I want the Purdue link to be active within the comment, so the students
can simply click it from their graded essays. Is this possible? Tag: document template Tag: 113204
Edit/Replace Text within Hyperlinks
I have a .doc which has about 35 hyperlinks to a shared folder. I would like
to do an edit/replace of "2007" with "2008" across all hyperlinks.
Example:
Hyperlink is
\\MyServer\FolderXXXX\SubFolder\PlanningTools\2007\_Category\2007Priorities
byChannel.ppt
Replace with:
\\MyServer\FolderXXXX\SubFolder\PlanningTools\2008\_Category\2008Priorities
byChannel.ppt
Does anyone know of an easy way to do this? I'd rather not edit each
individually...
Thanks
TOMB Tag: document template Tag: 113196
Question on Ranges
Dear Programmers,
I am stumped about why "oRange" is doing what it is doing and wondered if
someone could explain it to me (and/or point me in the right direction). We
are using Word 2003 and the macro is in VBA. Here is my code (it's from the
very beginning of the macro):
Dim oRange As Range
Set oRange = ActiveDocument.Tables(2).Range
With oRange
'collapse oRange to a point at the end of Table 2:
.Collapse wdCollapseEnd
'insert next-page-section-break right after Table 2:
.InsertBreak wdSectionBreakNextPage
'insert a paragraph right after the section break:
.InsertParagraphAfter
'
'If I understand correctly, the insertion point
'at this point should still be where oRange was
'collapsed--at the end of Table 2.
End With
oRange.Select
With Selection
.TypeText "TOC"
End With
'
' But here, "TOC" appears right after
' the inserted paragraph, not right
' after Table 2. Isn't oRange now still
' just a point after Table 2?
Any feedback greatly appreciated.
Thanks so much!
-Lynne Tag: document template Tag: 113195
Word 97 Macro to Create Outlook '03 Email With Text Format
Perhaps this should be in the Outlook discussion group, but I use a Word 97
macro that creates an email with Outlook 2003.
That email uses the contents of the current Word document as the body of the
email.
Test formatting is lost in the process. Any way to maintain (bold,
underline, colour, etc.)?
Thank you.
PS: The macro is from http://word.mvps.org/FAQs/InterDev/SendMail.htm:
Sub SendDocumentInMail()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = "recipient@mail.com"
'Set the recipient for a copy
.CC = "recipient2@mail.com"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With
If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub Tag: document template Tag: 113193
How can I Have the TAB key function normally in a Form text field.
When I'm in the Form text field environment, when using my TAB key, it jumps
to the next field or the top.
How can I have my TAB key funciton within the Form text field similar to a
text area in a word document? Tag: document template Tag: 113190
How to achieve editable word document with 95% protected in this c
Hi,
I am working with word-2003 templates having macro forms in it.
I use auto-text entries of 15-20 pages along with bookmarks giving options
to the
user in macro VBA forms to enter the fields . The user can insert the name,
address and check or uncheck the desired autotext entries(i.e autotext
entries have bookmarks where the bookmark text will be later replaced by the
user inserted fields). After insertion, the generated document will be
protected. There is a problem in the protection of this generated document
from template. I need the generated document (i.e after user entered his
requirements in the forms of template) to be protected in such a way that
user can make changes only to specific bookmarks in the generated document
(i.e even for auto-text entered bookmarks- name, address, etc in the
protected document). The generated document should be well protected allowing
only changes in the required bookmarks. Can you help me in the option of
editing the bookmarks in the generated document(i.e protected one)? Is there
any macro forms VBA code to do? or Should i use of the MS word protection
options only?
In Word-2003, I see the option of editing desired text in the protected word
document directly. I am unable to load the autotext entries with editing
enabled bookmarks.
In Macro VBA forms , I noticed the four options ActiveDocument.Protect( )
[wdallowonlyreading, wdallowonlyformfields,wdnoprotection,etc]. I am unable
to get my required result. Can any MVP help me in this issue? Tag: document template Tag: 113177
COMException when editing range and HRESULT: 0x80010105
Hi all, I'm not sure if this is the right place to post this, but:
I am trying to work with the PIA for microsoft word from VS2008, framework
3.5. I am working in a class library with a reference to the Office 12 PIA.
I have Office 2003 (only) installed.
I am getting a lot of exceptions I do not understand and I cannot find
documentation to explain, so any help would be greatly appreciated (as well
as documentation, if anyone knows of any).
First, trying to edit a range is always throwing an exception, whether it in
this format (I'm just pasting some of the relevant lines from the code):
oTable = doc.Tables[iTable]
oRange = oTable.Rows[iRow].Cells[3].Range;
oRange.Text = ""; // exception thrown here
Or if the last line is written like this instead:
object count = oRange.Characters.Count;
object charUnit = WdUnits.wdCharacter;
oRange.Delete(ref charUnit , ref count); // throws exception
In the second case the exception message is:
"Cannot edit Range."
In the first case I get HRESULT: 0x80010105 exception where the code stack
shows that the exception occurred in "set_Range" method in the RPC server.
Here are two more examples that return this same HRESULT: 0x80010105:
The last line in this code that is working with a Document word object
(called "doc") throws an exception:
Range oRange = doc.Content;
oRange.Find.ClearFormatting();
oRange.Find.MatchWildcards = true;
oRange.Find.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter; // throws exception
The following line also throws an exception:
oTable.Cell(iSide1Row, 2).Range.Text = strOriginal;
Where I've checked that both "strOriginal" and "oTable.Cell(iSide1Row,
2).Range.Text" evaluate to proper strings.
Tell me if you need to see more code. Tag: document template Tag: 113176
Deleting user-defined paragraph styles that have got "_Diss" at the
Dear Experts:
I'd like to delete all custom-defined paragraph styles in a document.
All these user defined paragraph styles have the following syntax
(*_Diss). How can I delete all theses styles in one go using Word VBA.
Help is appreciated. Thank you very much in advance.
Regards, Andreas Tag: document template Tag: 113172
OrganizerCopy Problem
I'm trying to copy a macro from the active document to a document
which has just been created. The macro is not in the Normal.dot
template, just in the active document. The code looks like:
Dim DocA As Document, DocB As Document
Set DocA = ActiveDocument
' Create new document
Set DocB = Word.Documents.Add(DocA.AttachedTemplate.Name)
'Copy macro to new doc
Application.OrganizerCopy Source:=DocA, _
Destination:=DocB, _
Name:="CreateCustom", _
Object:=wdOrganizerObjectProjectItems
I'm having two problems: first, I get a "Run-time error '4149': File
not found" error unless the current folder for Word is the the folder
with the two documents. Second, when the current folder is set to the
folder with the two documents, I get "Run-time error: '5940': The
project item cannot be copied.
The examples I've found for this have a .dot file for the source, but
I don't know what to do in this instance.
thanks in advance, dave Tag: document template Tag: 113171
How Does One Add a Page Number to a Header?
I would like to create a header so that: â??Add Title Hereâ?? appears on the left
side of the page, and â??Page {PAGE}â?? appears on the right side of the page. So
far I got:
Sub AddHeader()
Dim oRange As Range
Set oRange = ActiveDocument.Range(Start:=ActiveDocument.Range.Start,
End:=ActiveDocument.Range.End)
With oRange.Sections(1).Headers(wdHeaderFooterPrimary).Range
.Delete
.Paragraphs.Alignment = wdAlignParagraphLeft
.InsertAfter "Add Title Here" & vbTab & vbTab & "Page "
End With
End Sub
I would like a page number to follow: "Page ", I wish I could just add: &
vbPageNumber, but I suspect that it will be more complex than that.
Any help will be greatly appreciated.
Steven Craig Miller
P.S. I apologize for having wrongly placed a duplicate message in Word Tables. Tag: document template Tag: 113170
deleting form fields
I want to create a template form that after the document is created and
saved, the user can Open the saved document, run a "macro??" and delete only
specific fields in the form in one pass.
The original forms has ~200 fields. We want to be able to reOpen the
previously saved document, keep ~50 fields from the original and blank (or
Delete) the remaining ~150 fields with a single command. The feilds are
always the same.
What is the best way to solve this? I thought of building a macro but when
you run the macro on the filled in form, it takes a long time to remove the
fields in the document when the author is ready to type. VBA seemed like a
better option but I'm not as familiar.
Using Word 2003 on XP.
Thanks,
philr Tag: document template Tag: 113169
Word 2007 Not responding
I have the following macro that works fine in Word 2003. But when I try and
run it Word 2007 it locks up. I do not get an error message, Word 2007 just
stops responding. Any help would be appreciated.
On Error GoTo endthis
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.ParagraphFormat
.Alignment = wdAlignParagraphLeft
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "NOTE:^w"
.Replacement.Text = "NOTE:^t"
.Format = False
.Forward = True
.Wrap = wdFindStop
End With
Selection.Find.Execute Replace:=wdReplaceAll
Do While Selection.Find.Execute(Replace:=wdReplaceOne)
If Selection.Information(wdWithInTable) Then
With Selection.ParagraphFormat
.KeepWithNext = True
.KeepTogether = True
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.Collapse Direction:=wdCollapseEnd
Else
If Not Selection.Information(wdWithInTable) Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.ParagraphFormat
.Alignment = wdAlignParagraphLeft
End With
Selection.Font.Underline = wdUnderlineNone
Selection.Words(1).Font.Underline = wdUnderlineSingle
Selection.Paragraphs(1).Range.Select
Selection.ConvertToTable Separator:=wdSeparateByParagraphs, NumRows:=1,
numColumns:=1, _
DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:=wdAutoFitFixed
Selection.Tables(1).Rows.SetLeftIndent LeftIndent:=44,
RulerStyle:=wdAdjustNone
Selection.Tables(1).Columns(1).SetWidth ColumnWidth:=423,
RulerStyle:=wdAdjustNone
Selection.ParagraphFormat.Style = "tlNormal"
Selection.ParagraphFormat.TabStops(InchesToPoints(0.5)).Position = _
InchesToPoints(0.63)
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.63)
.KeepWithNext = True
.KeepTogether = True
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
With Selection.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.FirstLineIndent = InchesToPoints(-0.63)
End With
Selection.Collapse Direction:=wdCollapseEnd
End If
End If
Loop
endthis:
Selection.HomeKey wdStory Tag: document template Tag: 113168
Macro fine in Word 2000... breaks in Word 2002...?
Howdy,
I recently moved from Office 2000, to Office XP.
I have a bunch of macros that I built (in Word 2000) by
recording, and tweaking, rather than by having any real
understanding of VBA.
They worked fine, but...
Now that I run Word 2002, some of the macros choke.
The one below (with apologies for all the junk my recording
method includes) hangs at the pause that I have marked with
"XXXX", but will not run if I rem that line out.
'
' NameTagsFirst Macro
' Macro created 5/30/2002 by Kenneth
'
'
Documents.Add Template:= _
"F:\Templates\Label 4x2.dot" _
, NewTemplate:=False, DocumentType:=0
Documents.Open FileName:="Z:\Data\let.txt",
ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False,
PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
Selection.TypeText Text:="First" & vbTab
Selection.TypeParagraph
ActiveDocument.Save
ActiveWindow.Close
Selection.Font.Size = 36
Selection.Font.Bold = wdToggle
ActiveDocument.MailMerge.MainDocumentType =
wdFormLetters
ActiveDocument.MailMerge.OpenDataSource
Name:="Z:\data\let.txt", _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="",
SQLStatement:="", SQLStatement1 _
:=""
ActiveDocument.MailMerge.EditMainDocument
ActiveDocument.MailMerge.Fields.Add
Range:=Selection.Range, Name:="First"
Selection.TypeParagraph
' ActiveDocument.MailMerge.Fields.Add
Range:=Selection.Range, Name:="Last"
SendKeys "~"
ActivePrinter = "OKI"
With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True XXXXXXXXXXXXXXXXXXXXXXX
End With
ActivePrinter = "Printer Color"
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
Application.Quit
Might you assist in getting this to run properly?
Many thanks,
--
Kenneth
If you email... Please remove the "SPAMLESS." Tag: document template Tag: 113167
How to reverse only words into sentense by StrReverse function?
Hello.
I need to turn over all words in selected text by StrReverse function.
But these words should be in right order (like in sentense). Reversing
should be only for words, not for all string. For example, I do that:
Sub reverse()
Dim strStroka As String
Dim strRev As String
strStroka = Selection.Text
strRev = StrReverse(strStroka)
Selection.Text = Replace(strStroka, strStroka, strRev)
End Sub
This code is reversed all string. Thus the order of words into
sentense is broke. I try it otherwise, but I stop by using of cycle:
Sub reverse2()
Dim myArr() As String
Dim i As Integer
Dim sStr As String
Dim strRev As String
sStr = Selection.Text
myArr = Split(sStr)
For i = 0 To myArr(sStr) 'this is error
strRev = StrReverse(sStr)
Selection.Text = Replace(sStr, sStr, strRev)
Next i
End Sub
Help me, please.
Thank you very much. Tag: document template Tag: 113161
How to highlight text from the cursor's current position down to a
Hi,
May I ask how to write a macro that highlights text from the cursor's
current position down to any specific word, let say "name", in the
word document? Then, I want to delete the highlighted text. Thank
you.
Mike Tag: document template Tag: 113159
Beginning XML
Word Professional 2003
I am anxious to get started with learning at least the basic inâ??s and outâ??s
of working with XML. However, I seem unable to either locate or install from
the â??templates and add-insâ?? feature any schemas for use in beginning this
process.
I would be very appreciative of anyone who may perhaps be able to shed any
light on this situation for me as to how I might proceed.
Thanking you in advance â?? Rod Tag: document template Tag: 113153
How do I lock certain bits of text in a new template i am making? And does
anyone know how to create a shaded field where users can insert text?
See the replies to your posts in the .docmanagement group. Avoid
multiposting.
--
Stefan Blom
Microsoft Word MVP
"Megglesface" wrote in message
news:A5756C3B-E1E7-4FCE-B3E3-5B46A8DF4057@microsoft.com...
> How do I lock certain bits of text in a new template i am making? And does
> anyone know how to create a shaded field where users can insert text?