Identify tables with 2 columns and delete
Hi all,
I am trying to find all tables containing only 2 columns in a document,
select them, and then delete. Getting no where fast. Any suggestions
gratefully received.
Sub delTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
With ActiveDocument.Tables
If NumColumns = 2 Then
'If ActiveDocument.Tables.Count >= 1 Then
ActiveDocument.Tables.Select
Selection.Delete
End If
End With
Next oTbl
End Sub
Thanks,
--
Brian McCaffery Tag: how do i insert a brainstorm? Tag: 106796
Capturing a Content Control Range
Has anyone figured out a good way to capture a Content Control's Range? I
don't mean just the range of its text, but the text and it both.
I was working on some code to create a CC bound to CustomXML and then create
a BuildingBlock QuickPart of that control. I could never figure out a
simple way to define the range for the buidling block. If I simply used
.ContentControl(Index).Range the BB was just the text. Here is what I
finally put together but hoping one of you has a better way. Basically I
wrapped a bookmark around the Content control and then set the BB range to
the bookmark range:
Sub CreateBoundCC()
Dim oCustPart As CustomXMLPart
Dim oBMs As Bookmarks
Dim oRng As Word.Range
Dim oCC As ContentControl
Dim oBB As BuildingBlock
Dim oTemplate As Template
Set oBMs = ActiveDocument.Bookmarks
Set oCustPart = ActiveDocument.CustomXMLParts.Add
oCustPart.Load ("E:\Data Stores\mysample.xml")
Set oRng = Selection.Range
oRng.End = oRng.End + 1
oBMs.Add "Temp", oRng
Set oRng = oBMs("Temp").Range
oRng.Collapse wdCollapseStart
Set oCC = oRng.ContentControls.Add(wdContentControlText)
With oCC
.Title = "Clien Name"
.XMLMapping.SetMapping "/root/A", , oCustPart
End With
Set oTemplate = ActiveDocument.AttachedTemplate
oBMs("Temp").Range.End = oBMs("Temp").Range.End - 1
Set oRng = oBMs("Temp").Range
oBMs("Temp").Delete
Set oBB = oTemplate.BuildingBlockEntries.Add("Client Name",
wdTypeCustomQuickParts, "My Custom BBs", oRng)
Set oCustPart = Nothing
Set oBB = Nothing
Set oCC = Nothing
Set oBMs = Nothing
Set oRng = Nothing
End Sub
Thanks.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word. Tag: how do i insert a brainstorm? Tag: 106791
Autonew macro won't run
G'Day all!
Can someone please tell me why the following would suddenly stop running?
Private Sub Document_New()
UserForm1.Show
End Sub
I have created UserForm1 in my template and the form was loading correctly
on opening a new document based on that template. I have since edited the
fields on UserForm1 but the name is unchanged.
I am now getting:
Run-time Error '5941':
The requested member of the collection does not exist
Any suggestions gratefully received!
--
AnnieB
Basic Babe in the Woods Tag: how do i insert a brainstorm? Tag: 106772
Removing Line Breaks in Selected Text
I want to be able to select a few lines of text, and then remove all
the line breaks (only) in that selection and replace the linebreak
with a space.
How do I do that? The following code does not work properly. I am
using Word 2003.
Thank you.
---------------------------------------------------------------
Sub SelectionRemoveHardLineBreaks()
Dim oRng As Word.Range
Set oRng = Selection.Range
With oRng.Find
.Text = "^p"
.Replacement.Text = " "
End With
Do While oRng.Find.Execute
With oRng
.Find.Execute Replace:=wdReplaceOne
End With
Loop
End Sub
--------------------------------------------------------------- Tag: how do i insert a brainstorm? Tag: 106768
SLOW repsonse to recognize network printers
Hello,
The following code is attached to a letter template for which the paper
trays must be tray 2 and 1 on the printer 10st1_HP4350. I put the first line
of code in and the NE" & i & ":" to run through all possible numbers
following the NE, since I found that each day, the NE number was changing for
the printers. This code works, but is slow, and I need to add 16 more
printer names to the code. IT IS PAINFULLY SLOW.
I need code to change trays for the active printer detected when I run the
letter template, REGARDLESS of the number following NE, and it needs to be
very fast.
Any ideas??? Thanks so much!
Kurt
For i = MinNeNumber To MaxNeNumber
Application.ActivePrinter = "\\FS01\10st1_HP4350 on NE" & i & ":"
With ActiveDocument.PageSetup
.FirstPageTray = 261
.OtherPagesTray = 262
End With
Next Tag: how do i insert a brainstorm? Tag: 106767
Email Word Document
Thank you in advance for your time.
I have a button at the bottom of my Word document that reads "SUBMIT" When I
click the button, is there anyway it could email itself to a particular
person?
It keeps prompting me to enter the email address. I'm trying to get around
it so I don't have to type the address in everytime I submit.
I do appreciate your time.
thanks,
tim
tim Tag: how do i insert a brainstorm? Tag: 106766
Word 2007 Track Changes Customization
Is it possible to mark up insertions as both bold and doubleunderline?
Is it possible to turn off Track Changes warning for print, save etc.? Tag: how do i insert a brainstorm? Tag: 106754
Macro in mailmerge
Hi everyone!
I have written a macro to split the mailmerge document after we complete the
mailmerge , but there is a small problem here: I dont want to create an addin
so I just want to add the macro to a document or templete( not Normal.dot)
and be able to access it after the user complets the mailmerege but as most
of you know after creating a mailmereg word creates a new document based on
the fields and the macro is not accessable through toolbar button so I must
use the VBAeditor to run it. So my question is how can I have this splitmerge
macro in a document and be able to access it after completing the mail merge?
--
Best regards,
Edward Tag: how do i insert a brainstorm? Tag: 106752
Clear Formatting behaviour
In Word 2003 on WinXP:
If I use Clear Formatting on a string of text that has a character
style applied to it, the character style is removed from that string.
However, the paragraph style for the paragraph as a whole remains.
However, if I protect the document with formatting restrictions, then
the behaviour of Clear Formatting changes. In that case, if I use
Clear Formatting exactly as described above, then the whole paragraph
loses its paragraph style, as well as the character string losing its
character style.
This discrepancy is the same whether I am using the user interface or
VBA.
Anybody have any idea why, and what I can do about it? This is going
to clobber a feature I'm trying to put in play for my user set.
TIA--
--larry Tag: how do i insert a brainstorm? Tag: 106749
Autotext page numbering won't update!
I used autotexts for automatic page numbering that appear outside the
header/footer area:
{ page} of { numpages}
And it worked . . . initially. However, the "numpages" field won't
update even though more pages added. I tried switching the view mode,
closing and re-opening the file, etc., but still it won't update. Did
I miss any step, or is there any way to fix this problem?
PLEASE HELP!
Joy Tag: how do i insert a brainstorm? Tag: 106748
Upgrading from Word and Outlook 2003 to Word and Outlook 2007
I have several macros that "grab" addresses from Outlook and put them into my
form/letter in Word in 2003. Now that the upgrade has happened all the
autotext and the rest of my code works fine EXCEPT the get address part of
the code. It returns the value in my variables, however, it simply does not
return the value to the textbox fields in my form and of course does not put
it into the final letter document. Here is my code. Again, the variables (
rcpFirstName1, rcpLastName1, rcpAddress1) are returned correctly and the
frmContacts.txtName1.Value, frmContacts.txtC1.Value and
frmContacts.txtSal1.Value are also returned correctly. However, they do not
populate the fields on the dialog nor do they get entered into the final
letter.
Public Sub cmdOC1_Click()
DialogReturn = rcpDisplayName1 =
Application.GetAddress(AddressProperties:="<PR_DISPLAY_NAME>",
DisplaySelectDialog:=1)
rcpCompanyName1 =
Application.GetAddress(AddressProperties:="<PR_COMPANY_NAME>",
DisplaySelectDialog:=2)
rcpFirstName1 =
Application.GetAddress(AddressProperties:="<PR_GIVEN_NAME>",
DisplaySelectDialog:=2)
rcpLastName1 = Application.GetAddress(AddressProperties:="<PR_SURNAME>",
DisplaySelectDialog:=2)
rcpBusFaxNo1 =
Application.GetAddress(AddressProperties:="<PR_BUSINESS_FAX_NUMBER>",
DisplaySelectDialog:=2)
If rcpCompanyName1 = "" Then
strAddress1 = "<PR_POSTAL_ADDRESS>"
Else
strAddress1 = "<PR_COMPANY_NAME>" & vbCr & "<PR_POSTAL_ADDRESS>"
End If
rcpAddress1 = Application.GetAddress(AddressProperties:=strAddress1,
DisplaySelectDialog:=2)
'populate fields in frmContacts
If DialogReturn = False Then
frmContacts.txtName1.Value = rcpFirstName1 & " " & rcpLastName1
frmContacts.txtC1.Value = rcpAddress1
' frmContacts.txtSal1.Value = rcpFirstName1 & " " & rcpLastName1
mReturn10 = True
Else
mReturn10 = False
End If
End Sub
This macro is being used a LOT in quite a few firms so any help would be
greatly appreciated!
--
CLG Tag: how do i insert a brainstorm? Tag: 106738
How can I call a macro from an unviewable project
I have a macro in a template that I can manually run using the Tools-
Macros menu option. In the VBA editor though when I try and expand
the document it's from in the project pane I get a messagebox titled
"Project Locked" with a message of "Project is unavailable". I tried
manually writing the code to run it, but get an error 424.
ProjectName.ThisDocument.MacroName Tag: how do i insert a brainstorm? Tag: 106734
My INSERT FILE is busted
Group,
I have no clue how I accomplished this, but each time a new MSWORD 2003
document is created, I select INSERT, FILE, it automatically inserts a
document from something I've worked with in the past, (I'm not even sure
where this documents exists??) I no longer receive the dialog box to choose a
picture, a file, etc.., it's already chosen for me. I've reset my toolbar,
but still cannot INSERT a FILE of my choice, it automaticaly is choosing it's
own file. How can I get behind the INSERT FILE command?? Tag: how do i insert a brainstorm? Tag: 106733
Corrupted Documents
In our very large company, we have documents that have been around for years,
been modified by many users, and on different computers. As a result, the
documents are getting corrupted. This includes numbering that gets moved,
revisions that come and go by themselves, and headers realigning to name a
few.
Is there any way to restore the document or fix these corruptions? Tag: how do i insert a brainstorm? Tag: 106731
Word 2007: Options.ReplaceSelection -> Run-time error 4120 Bad Parameter
Hi,
In April, jalanford wrote a carefully composed message in
microsoft.public.word.vba.general on the subject of run-time errors when
trying to set a number of parameters like Options.[SomeParameter] via VBA.
The problem occured only on some machines with Word 2007 and Windows XP. We
can't reproduce it on our machines, and we have no direct access to machines
affected by the problem.
But we have the same problem with a small number of our customers and are
looking for the best way to make our add-in work on their systems - other
then writing a patch for our software, which we will do anyway. If the
registry is involved, even a patch will probably require some "manual"
action by the customer in certain cases. So far, we succest to run our Word
add-in on a newly created user account, which worked in all known cases, but
is far from ideal, of course.
Unfortunately, the discussion then in the newsgroup stopped before someone
provided a solution. The only suggestion was to repair the registry, but
there was no follow-up.
Could jalanford or someone else please give some advice how you worked
around the problem? If so, I would try to compile an answer to the problem
for the newsgroup.
Thanks in advance
Hans Tag: how do i insert a brainstorm? Tag: 106728
Macro to be available in documents based on a template
I would like a macro I have created in a template (.dot) to be available in
documents (.doc) created from the template (ie. when other people in my
workplace double-click on the template. At the moment, when I double-click
on the template (it creates a .doc version of it )and I go to the list of
macros, the macro I created doesn't show up in the .doc version. What am I
doing wrong. Thank you for any assistance you can offer. Tag: how do i insert a brainstorm? Tag: 106724
Compacting access database using VB
Hi,
This is actually an MS Access problem, but i thought i'd put it here as
well. If anyone can help....
I am working on a database and on a specific form i have a button for
'Compact Database'. Now the code i use to compact onClick of the button is:
CommandBars("Menu Bar").Controls("Tools").Controls("Database
utilities").Controls("Compact and repair database...").accDoDefaultAction
This works fine except if a guy in say, japan, uses it and has a japanese
language pack, then access cant find "Menu Bar", "Tools", etc. cause they are
in english in the code and in japanese in access and a problem occurs.
so i wanted to know if there is a different way to compact where i could
probably use some internal properties etc. and where language wont be a
problem. I need to compact an active database.... Tag: how do i insert a brainstorm? Tag: 106723
HP Desktop for sale!
Hi,
I have an unused HP Pavilion with the fallowing specs:
# Processor: AMD Athlon 64 X2 4000+ (2.1GHz, 2000MT/s System Bus)
# Memory: 2048MB PC2-5300 DDR2 SDRAM memory (2x1GB) (expandable to 8 GB (4 x 2 GB) (64-bit OS)/ 4 GB (4 x 1 GB) (32-bit OS))
# Hard Drive:320GB 7200RPM SATA 3G (3.0 Gb/sec) hard drive
# Optical Drive: 16X DVD(+/-)R/RW 12X RAM (+/-)R DL LightScribe SATA drive
# Expandable Drive Bay: HP Pocket Media Drive bay
# Video Graphics: Integrated graphics
# Network Interface: Integrated 10/100BaseT network interface
# Sound: High Definition 8-channel audio
# Fax/Modem: 56K bps data/fax modem
# Operating System: Genuine Windows Vista® Home Premium
This is "used" but basically brand new (it has literally been on for no more than 6 total hours..) is only 1 month old..
PRICE: $425 OBO
Email- pbdude911@yahoo.com Tag: how do i insert a brainstorm? Tag: 106714
Watch NFL Games Online
Watch NFL Games Online!
For every one who wants to watch the games online because they dont live in the teams town or are at work i found a site that has basically every game covered. Its perfect if you have afford a monthly $70 direct tv nfl access subscription. they got a bunch of channels
The sites http://nflonline.wizhoo.com Tag: how do i insert a brainstorm? Tag: 106713
Protected Form Fields in Header Area
I have a question regarding the header/footer in a protected form.
Is
there a way to insert form fields in the header/footer in a protected
MS Word form? When an user opens the form file, I'd like the person
to go to the header and fill in the form fields, close the header,
and then fill in the rest of the form. And the header information
should repeat every page of the form. Right now it seems that when
protected, the user cannot access the header. Can anyone help me
with
this issue, if there's a way around it? Thank you!
Joy Tag: how do i insert a brainstorm? Tag: 106711
Fatloss computer program
I have been using this computer program for a couple weeks now and i am very pleased with the results so far. its a software fatloss program, if your looking for a diet/weightloss plan i reccomend you check this place out first: http://fatloss9.50webs.com Tag: how do i insert a brainstorm? Tag: 106710
Automatic update of footer macro
I'm posting this for a user who sent me the following query, which I've
inserted below as submitted to me:
"Hi ,
Don't know if you know any VBA but I have a problem that I haven't been able
to resolve. I don't know any VBA but I can usually cheat by looking
something up via google or recording a macro and transferring and altering
parts of the code to do what I need it to do. But I haven't been able to
figure this one out:
I have a footer macro that I set up to include the "last author" and "last
modified" items rather than the current date/time and the original author.
The problem with my footer is that it doesn't update these items
automatically when I save. It will only update if I re-run the macro to
insert the footer. (This is the same problem as with using the regular
pathname footer in Excel - which doesn't update when you use save as and save
a file with the pathname in the footer to a new location.)
Sub Footer()
'
' Footer Macro
' Macro recorded 3/26/2007 by atao
'
ActiveSheet.PageSetup.LeftFooter = "&8Last Modified by " & ActiveWorkbook. _
BuiltinDocumentProperties("last author").Value & " " &
ActiveWorkbook. _
BuiltinDocumentProperties("last save time") & Chr(10) & "&Z&F\&A"
ActiveSheet.PageSetup.RightFooter = "&8&P of &N"
End Sub
So, I am either trying to find a way for those items to auto-update as does
current date and time (when you use &[date] &[time] (which I have a feeling
can't be done for Builtin Document Properties or have the macro re-run
automatically upon saving. I found something called "OnAction" property that
may do the trick when save is pressed but I actually don't know any VBA so I
thought maybe you would be able to help me?" Tag: how do i insert a brainstorm? Tag: 106705
linked drop down text box
i have a word form with a drop down text box. depending on what is chosen i
would like two other boxes to be populated. Can anyone point me in the right
direction? Tag: how do i insert a brainstorm? Tag: 106697
Help with inlineshpae textbox
hello,
I have a form with a number of textboxes embedded as inlineshapes, each of
which have a dblclick event assigned to them - this works just fine. I
would very much like to have a seperate click event to do something else,
but a textbox (as an inline shape) does not have a click event. I tried
using a mousedown event, but this activated before I could double click it.
Embedded labels do have both click and doubleclick events, and these work
but are not what I need for this application.
here is what the double click does: , the single click would have to start
a different subroutine.
Private Sub TBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
TBox1.Text = ChangeTextBoxText(GetILS, TBox1.SelStart, TBox1.Text)
End Sub
Thanks Jim Tag: how do i insert a brainstorm? Tag: 106694
Can you suggest modifications to speed up this function?
What I am trying to do it to go through a list of Word documents and create
an array containing two parameters for each TOC entry. The first entry is
made up of the filename, a "|" as a delimiter and the TOC entry text
(includes all levels up to that point concatenated with a >). The second
entry of the array is the page number associated with the TOC entry. This
works as it is but it is painfully slow. I added the flag that is set when
the TOC Title paragraph is found to be able to stop the processing once all
of the TOC # entries had been processed and that has helped some but this is
still very slow. Is there a different approach that would speed this up?
Thanks.
Private Sub GetDocumentsHeadingsForFileInPath(wordFileName, wordFilePath)
Dim oApp As Object
Dim oDoc As Object
Dim oSec As Object
Dim NumSections As Integer
Dim foundTOC As Boolean
Dim st As String
Dim tocLastValues(9) As String
'Start Word and open the document.
Set oApp = CreateObject("Word.Application")
On Error Resume Next
Set oDoc = oApp.Documents.Open(wordFilePath)
If Not oDoc Is Nothing Then
'Iterate each paragraph in the document to find the table of content
entries
'Get their level, text and page values
'Once you have found the Table of Contents, stop at the next style
that is not a TOC #
NumSections = oDoc.Paragraphs.Count
foundTOC = False
For i = 1 To NumSections
Set oSec = oDoc.Paragraphs(i)
If Not oSec Is Nothing Then
st = oSec.Style
If st = "TOC Title" Then
foundTOC = True
ElseIf Left(st, 3) = "TOC" Then
currentLevel = Right(st, 1)
currenttext = Split(oSec.Range.Text, vbTab)(0)
currentPageNo = Split(oSec.Range.Text, vbTab)(1)
currenttext = GetFullTextForLevel(tocLastValues,
currentLevel, currenttext)
'Debug.Print "Level: " & currentLevel & " Text: " &
currenttext & " Page: " & currentPageNo
allValues(0, noEntries) = wordFileName & "|" & currenttext
allValues(1, noEntries) = currentPageNo
noEntries = noEntries + 1
ElseIf foundTOC Then
Exit For
End If
End If
Next
End If
'Close the document without saving changes and quit Word.
On Error Resume Next
oDoc.Close
oApp.Quit
Set oSec = Nothing
Set oDoc = Nothing
Set oApp = Nothing
End Sub
Private Function GetFullTextForLevel(currentValues, thisLevel, levelText)
Dim i As Integer
Dim tempText As String
tempText = ""
'blank out everything above this level
For i = thisLevel To 9
currentValues(i) = ""
Next
'set this level's text
currentValues(thisLevel) = levelText
'build the string for this level
For i = 1 To thisLevel - 1
tempText = tempText & currentValues(i) & " > "
Next
tempText = tempText & currentValues(thisLevel)
GetFullTextForLevel = tempText
End Function Tag: how do i insert a brainstorm? Tag: 106692
Find String, Copy/Paste Next 255+ Characters to New .doc
Does anyone know of a way to search for a certain string, such as
â??Additionalâ?? and then copy/paste this into a new document, along with the
following 255 characters? Is 255 the limit? I found the code below on this
DG:
Sub RTM4()
Dim oDoc As Document
Dim oSrcRg As Range, oDestRg As Range
Set oSrcRg = ActiveDocument.Range
Set oDoc = Documents.Add
Set oDestRg = oDoc.Range
oDestRg.Collapse wdCollapseEnd
With oSrcRg.Find
.ClearFormatting
.Text = "Additional ?{255}"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Do While .Execute
oDestRg.FormattedText = oSrcRg.FormattedText
oDestRg.Collapse wdCollapseEnd
oDestRg.InsertParagraph
oDestRg.Collapse wdCollapseEnd
Loop
End With
Set oDestRg = oDoc.Range
oDestRg.ConvertToTable Separator:=wdSeparateByTabs, _
NumColumns:=3, NumRows:=100, _
AutoFitBehavior:=wdAutoFitFixed
With oDoc.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
oDoc.Activate
Set oSrcRg = Nothing
Set oDestRg = Nothing
Set oDoc = Nothing
End Sub
It works great. Sometimes the string, such as â??Additionalâ?? is in a table,
and the code seems to struggle with the tables sometimes. For instance, if I
have the word â??Additionalâ?? in one table, I'd like to find 255 characters, or
more, up to 500 characters, in an adjacent table, just to the right on this
table. Any suggestions?
Regards,
Ryan
--
RyGuy Tag: how do i insert a brainstorm? Tag: 106690
INCLUDETEXT w/DOCVARIABLE
I have two documents, â??DOCUMENT Aâ?? reads, â??Thank you for the amount of
{docvariable MONEY}, etc.....
â??DOCUMENT Bâ?? reads: â??I received your payment,, {include text
\\server\path\documentA.doc}. Your prompt payment etc, etcâ?¦â??
The problem is when DOCUMENT B is opened by a user to complete, â??DOCUMENT
Aâ?? is inserted but it does not include the {docvariable MONEY}â?? â?? only the
text.
Is there another field that I should be using instead of the INCLUDETEXT?
Is this my problem, the INCLUDETEXT statement? â??
Diane Tag: how do i insert a brainstorm? Tag: 106688
MVP Userform How2 question for Doug Robbins
At the MVP website location:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
...Under Step 2, Doug says that after creating a bookmark, "You can then use
a cross reference to the text of the bookmark if you want the same
information to appear in another location."
Several of the items in my userform need to appear in multiple locations
throughout the document, but so far, my experiments with cross references
produce no success. In fact, when I place the cursor in those other locations
and try to insert a cross reference to the original bookmark, nothing gets
inserted. What am I missing?
Thanks, Tag: how do i insert a brainstorm? Tag: 106687
need code to copy paste extended
Hi All,
I need some VBA code that will Copy a highlighted part of a document
to the clipboard including
the name of my document (ActiveDocument.Name).
So when I paste it in a new blanc document I will have the highlighted
text and at the end of it my filename, like:
"This is my highlighted text which was copied from another document".
MySourceDoc.20071018.doc
Marco Tag: how do i insert a brainstorm? Tag: 106685
Word support for Resource Protocol(res)
Hi,
I have a html page with an IMG tag as shown below
<img src="res://MyDLL.dll/IMAGE/XYZ" id="IMG3" />.
This html page when opened in internet explorer, will display the page with
image properly. But when i insert this file in word document, the image is
not getting displayed. Please let me know whether there is a way to render
resources from an assembly into a word document.
Thanks,
Best Regards,
Ram. Tag: how do i insert a brainstorm? Tag: 106682
How to remove specifik emty lines after data merge in word200x
I have at problem with data merge from CRM system to Word200x. The problem is
that the CRM system send all data from CRM to Word tempalet and some Parmeter
is emty, but word do a next line(a emty line"field"). How to auto remove this
emty fields
Customer Compani name
attension name (that field could be emty, but not always)
add. zip code
...
..
How to do that ?
Regards
Eravn Tag: how do i insert a brainstorm? Tag: 106677
Word Open event
I want to have some code to run as Word (client opens Word) opens.
However I can not find the right Event. I thought it will do so at
Document_New(), but this event is happening when you hit the New Icon.
What event is happening as soon as Word opens?
Thanks,
Dirk Tag: how do i insert a brainstorm? Tag: 106675
Hide/show bookmark through macro
what would i put in to a macro to hide/show a section of text whichi is
bookmarked?
Using xp and w2007.
Many thanks. Tag: how do i insert a brainstorm? Tag: 106659
Access to the properties with the Quick Part
Hi,
There is a list of properties accessible with Content Controls through Quick
Parts.
The list of the properties accessible this way is very limited.
Is it possible to add Content Control binded to any property not available
on Insert/Quick Part/Property menu?
Is it possible to bind custom property to the Content Control?
Thank you,
--
Maxim Tag: how do i insert a brainstorm? Tag: 106658
Validate Inputbox entry
It seems like there should be a cleaner way of doing this. I want the user
to enter a valid date in a inputbox and set the value of the input box to a
string.
Sub CalcAge()
Dim pStr As String
Do Until IsDate(pStr)
pStr = InputBox("Enter the birthdate", "Birthdate")
If Not IsDate(pStr) Then
MsgBox "Please enter a valid date"
End If
Loop
'More code here.
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word. Tag: how do i insert a brainstorm? Tag: 106656
cursor won't move to selection
My code is below. It works fine, moving from textframe to textframe
and asks the user about making changes to the text in the textframe
BUT the cursor and or screen doesn't move to the next location, it
just stays on page one. Screen update, maybe?
Sub fixTextBoxes()
Dim s As Shape
For Each s In ActiveDocument.Shapes
With s.TextFrame
If .HasText Then s.Select
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to Remove strikethrough and change font
color to black?" ' Define message.
Style = vbYesNoCancel + vbCritical + vbDefaultButton2 '
Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes
Selection.Font.Color = wdColorBlack
Selection.Font.StrikeThrough = False
If Response = vbCancel Then Exit Sub
Else ' User chose No.
MyString = "No" ' Perform some action.
End If
End With
Next
End Sub Tag: how do i insert a brainstorm? Tag: 106637
Renaming documents from text within the document using existing Ma
I've been working with the following Macro to seperate a large document into
individual documents. The Macro saves these new documents as "test_1.doc",
"test_2.doc," etc. Everytime I run the macro, I have to then go back and
rename all the documents manually. The first line of the document always
begins with "Name:" and I rename the document simply by copying and pasting
the name that follows. Is there a way to have the macro do this for me?
Something that tells it to copy line 1 col 7-50 and paste into the FileName?
Sub BreakOnSection()
' Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mail merge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
'Note: If a document does not end with a section break,
'substitute the following line of code for the one above:
'For I = 1 To ActiveDocument.Sections.Count
'Select and copy the section text to the clipboard.
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\My Documents"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close
' Move the selection to the next section in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub Tag: how do i insert a brainstorm? Tag: 106635
Reading a txt file and updating fields
Hi
I must have develop a solution and don't know how...
When the user opens a Word document, a macro must be executed (using
AutoOpen(), perhaps?), read a separated .txt file and with this information
updating the fields in the document (DOCVARIABLE). The name of the
DocVariables are referenced in txt file like document_version=1.0...
Somebody can help me, please? Tag: how do i insert a brainstorm? Tag: 106634
Macro very slow in Word 2003
Back in June, I posted a problem on this newsgroup about as macro that
searches for a regular pattern in table cells and defines tab
positions if the pattern is found (Thread 'find, format tabs and
replace in table cells'). Thanks to Helmut Weber, my initial attempt
was greatly improved and worked at an acceptable speed in Word 2000
(from 25 seconds on a 19 page document to .375 seconds!).
But now I've got Word 2003 and I'm also working on larger documents
(60 pages) and processing time has increased to 6 minutes. I suspect
that memory problems are playing up as well since another macro
creates garbage if run after this first one, whereas it runs perfectly
if I save and quit Word before running it. Does anyone have any
suggestions on how to improve the performance of this macro?
(From my posting on June 27: I've got tables with counts and
percentages in many of the table cells
in the form "35.3% (47/133)". I want the percentages to align so I
wrote a macro to define right-aligning tab positions at 40% and 100%
of the cells usable width and then insert a tab character between the
percentage sign and the opening parenthesis.)
Advance thanks for any help,
John Hendrickx
Public Sub TabsForPctAndCount()
Dim t As Single
t = Timer
Dim aRange As Range
Dim oCell As Cell
Dim UseableWidth As Single
Set aRange = ActiveDocument.Range
System.Cursor = wdCursorWait ' Displays the hourglass
Application.ScreenUpdating = False
With aRange.find
.Text = "([0-9.]{1,8}%)[ ]{1,5}\("
.Replacement.Text = "^t\1^t("
.MatchWildcards = True
While .Execute
If aRange.Information(wdWithInTable) Then
.Execute replace:=wdReplaceOne
Set oCell = aRange.Cells(1)
UseableWidth = _
oCell.Width - oCell.LeftPadding -
oCell.RightPadding
oCell.Range.ParagraphFormat.TabStops.ClearAll
oCell.Range.ParagraphFormat.TabStops.add _
Position:=UseableWidth * 0.4,
Alignment:=wdAlignTabRight
oCell.Range.ParagraphFormat.TabStops.add _
Position:=UseableWidth, Alignment:=wdAlignTabRight
aRange.Start = oCell.Range.End + 1
aRange.End = ActiveDocument.Range.End
End If
Wend
End With
System.Cursor = wdCursorNormal ' Normal cursor
Application.ScreenUpdating = True
StatusBar = "Macro TabsForPctAndCount completed."
MsgBox Timer - t
End Sub Tag: how do i insert a brainstorm? Tag: 106630
Annoyance: Documents opening in markup mode
I think my word is configured to open in markup mode, because no matter if I
save a document in normal or print, it always appears in markup mode as
well.
I don't want it, so I recently added the following code to my documents, to
switch off markup mode, when the document is opened.
Sub Document_Open()
WordBasic.ViewChanges
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
End Sub
Is there a way to switch markup mode off through word options, or is there a
way to add the above code to my personal macro workbook, so that all
documents open normally?
Kind regards
Dylan Tag: how do i insert a brainstorm? Tag: 106628
How to create a toggle button for a toolbar command
Hi there,
First, I have never written a visual basic program or code or however it is
called, only recorded macros a few times and looked at the code (?) in the
Visual Basic Editor. Therefore, if anyone can help me, I'm afraid I will need
the complete code (or whatever) that I can just paste into VBA and - hey
presto!
I am working with WORD 2003 and found out, thanks to this discussion group,
that in order to use "select all instances" of a style I have to click "Keep
track of formatting". Well, I do hate "Keep track of formatting" because it
generates these stupid styles like "block text bold" etc. But, on the other
hand, I sometimes would like to find all instances where a certain style is
used in a document. For this purpose, I want to create a toggle button that
switches on and off the "Keep track of formatting" function.
I have recorded a macro to click "keep track of formatting" and it looks
like this:
Sub TrackFormatting()
'
' TrackFormatting Macro
' Application.DisplayStatusBar = True
Application.ShowWindowsInTaskbar = True
Application.ShowStartupDialog = False
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayLeftScrollBar = False
.StyleAreaWidth = CentimetersToPoints(0)
.DisplayVerticalRuler = True
.DisplayRightRuler = False
.DisplayScreenTips = True
With .View
.ShowAnimation = True
.Draft = False
.WrapToWindow = False
.ShowPicturePlaceHolders = False
.ShowFieldCodes = False
.ShowBookmarks = False
.FieldShading = wdFieldShadingWhenSelected
.ShowTabs = False
.ShowSpaces = False
.ShowParagraphs = False
.ShowHyphens = False
.ShowHiddenText = False
.ShowAll = True
.ShowDrawings = True
.ShowObjectAnchors = False
.ShowTextBoundaries = True
.ShowHighlight = True
.DisplayPageBoundaries = True
.DisplaySmartTags = True
End With
End With
With Options
.ReplaceSelection = True
.AllowDragAndDrop = True
.AutoWordSelection = False
.INSKeyForPaste = False
.PasteSmartCutPaste = True
.AllowAccentedUppercase = False
.PictureEditor = "Microsoft Office Word"
.TabIndentKey = True
.Overtype = False
.AllowClickAndTypeMouse = False
.CtrlClickHyperlinkToOpen = True
.AutoKeyboardSwitching = False
.PictureWrapType = wdWrapMergeInline
.DisplayPasteOptions = False
.PromptUpdateStyle = True
.FormatScanning = True
.ShowFormatError = False
.SmartParaSelection = False
.SmartCursoring = True
End With
ActiveDocument.ClickAndTypeParagraphStyle = "Normal"
End Sub
Well, there seem to be quite a lot of things in this that probably are not
necessary for my purpose. And I can't identify which line refers to my "keep
track of formatting" function....
But, more important, I have no idea what to do now. I can assign a button to
this macro, but how can I make this button toggle between the two states, so
that I can click and unclick "keep track of formatting"? I am totally
helpless. Tag: how do i insert a brainstorm? Tag: 106623
Converting Visual Basic inside Word Document to VBScript
Hello,
I am trying to put MS Word COM Objects in to a VBScript - I am struggling
with a bit of translation.
Basically I want to alter a Heading style.....
I use Word Macro to get me the code, which is....
objSelection.Style = ActiveDocument.Styles("Heading 1")
With ActiveDocument.Styles("Heading 1").ParagraphFormat
.LeftIndent = CentimetersToPoints(1.27)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 3
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = True
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(-0.63)
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
How do I put that in to VBScript??
I understand I have to create the object and create a new document (as below)
set objword = CreateObject("Word.Application")
objword.visible = True
set objDoc = objword.Documents.Add()
set objSelection = objWord.Selection
What else do I need to do??
Many Thanks in advane
Mark Holland Tag: how do i insert a brainstorm? Tag: 106622
How can I determine presence insertion point into some table?
There is one macro which applies to table in which there is insertion
point. If insertion point there not exist (insertion point is there
out of table) then we is of error.
How can I determine is there is insertion point into any table or not?
Thank you! Tag: how do i insert a brainstorm? Tag: 106614
Copying hyperlink including nametag
Hello all, I haven't posted here in quite a while.
The below macro copies the first hyperlink in the document. However, when
the hyperlink includes a nametag, the copy does not include the name tag.
For example, if the first hyperlink in the document is
http://www.mysite.com/xxxx.html#test
what the macro puts in the Clipboard is
http://www.mysite.com/xxxx.html
For whatever reason, the code
ActiveDocument.Hyperlinks(1).Address
does not include the nametag.
Is there any way I can get this macro to copy the nametag if there is one?
Thanks.
Here's the macro:
If ActiveDocument.Hyperlinks.Count = 0 Then
Exit Sub
End If
Dim MyData As DataObject
Dim strURL As String
strURL = ActiveDocument.Hyperlinks(1).Address
Set MyData = New DataObject
MyData.SetText strURL
MyData.PutInClipboard Tag: how do i insert a brainstorm? Tag: 106601
how to make a read-only word file in word 2003?
Hi ,
how to make a read-only word file in word 2003?
thank you in advance,
best regards.
davidxu Tag: how do i insert a brainstorm? Tag: 106600
Automatic Page Numbering Outside Header/Footer
Hi! I'm trying to insert Page No. and No. of Pages text form fields
(# of # format) in a protected MS Word form, but not inside header/
footer areas. Is this possible by using macros, autotexts, etc.? If
it is, can anyone help me on this?
Joy Tag: how do i insert a brainstorm? Tag: 106596
Calculating time differences?
How would I get Word to calculate time as in a time sheet, such as:
In Time 8:00AM
Out Time 12:30PM
Word would give me 4.5 from that... Tag: how do i insert a brainstorm? Tag: 106590
How to replace a string of characters with the count of the charac
I have what seemed at first to be a trivial task for a Word 2003 SP2 macro
(VB 6.3).
Given a body of text containing a range of characters (letters (upper and
lower case), digits, punctuation, spaces), all but the letters A-Z need to be
removed, then the resulting text needs to be sorted, and finally, the count
of each letter should replace each block of sorted letters.
So: â??I wandered lonely as a cloud, that floats on high oâ??er vales and hills,
etc., etc., with a few 12345 thrown in for good measure!â?? becomes
penultimately:
â??AAAAAAAAACCCDDDDDEEEEEEEEEEFFFGGHHHHHHIIIIILLLLLLLMNNNNNNOOOOOOOOORRRRRSSSSSTTTTTTTUUVWWWWYâ??
and then finally: 9 0 3 5 10 3 2 6 5 0 0 7 1 6 9 0 0 5 5 7 2 1 4 0 1 0. (The
zeros appear where a letter in the sequence is missing and so the count for
that letter is zero).
I did some searching around and found very useful information on the use of
Search/Replace with wildcards from Graham Mayor and Klaus Linke at
word.mvps.org (excellent job â?? thank you!. Iâ??ve been using MS Word for
probably 15 years and I still find something to learn :))
My initial code worked OK â?? my approach was to first select the entire body
of text and render it upper case, then use Search/Replace with the FIND
wildcard sequence [!A-Z] and the REPLACE sequence null to reduce the text to
solely A-Z.
A subsequent Search/Replace on the text added a carriage return after every
character, the result was sorted, followed by another Search/Replace to
remove all the carriage returns. (There may be a quicker/simpler way but Iâ??m
not aware of it.)
When it came to replacing each block of the same letter with its count, I
hit a snag. Try as I might, I cannot find a simple programmatic way to do
what I want.
I thought I had a solution when I tested a manual approach, using FIND with
Highlight checked (so the count is returned, but more importantly the block
of matching text is selected on exiting FIND, so that â?? I thought â?? I could
just replace the selection with the contents of Selection.Characters.Count
(and add a space as a separator).
Not so. What works manually doesnâ??t appear to work in a macro.
If I create a macro (even if I record one) that uses FIND to locate and
select all matching characters, upon completion only the first character in
the group is selected, whether I use Selection or Range.
I havenâ??t found a bug report that describes the FIND problem â?? yet â?? and
there are clearly more complex workarounds that I could devise, but Iâ??d
prefer to keep the solution minimal and simple if I can. Iâ??d be very grateful
for some guidance, even if itâ??s to say: â??Use a workaround; FIND is bugged.â??
Best,
Peter
Example code:
Sub M8()
'
' Macro M8 created 10/15/2007 by Peter GQ Brooks
'
' Sort the text. Simplest way is to begin by making everything upper case
(A-Z), then use
' Search/Replace to remove everything that is NOT in the range A-Z (use
wildcards and the
' expression [!A-Z] for the FIND and null for the REPLACE).
' Then replace every character with itself plus a carriage return, making
each character a
' line on its own, then sort, then delete all carriage returns (replace
every carriage return
' with a null).
' Select the entire document.
' Change case to upper.
Selection.WholeStory
Selection.Range.Case = wdUpperCase
' Ensure Find/Replace boxes have no prior formatting to impede process
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
' Dump everything that isn't in the range A to Z.
With Selection.Find
.Text = "[!A-Z]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Now look for "any single character" and replace it with the same character
and a carriage return
With Selection.Find
.Text = "^?"
.Replacement.Text = "^&^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Sort entire document by paragraphs
Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldAlphanumeric,
SortOrder:=wdSortOrderAscending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric,
SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending,
Separator:= _
wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False,
LanguageID _
:=wdEnglishUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
' Remove all carriage returns after sorting.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Loop from A to Z and replace with count of character
For asciipointer = 65 To 90
Selection.Find.ClearFormatting
With Selection.Find
.Text = Chr(asciipointer)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Experimental section, trying various solutions:
' Set myRange = ActiveDocument.Content
' myRange.Find.Execute FindText:=Chr(asciipointer), Forward:=True
' Stop
' If myRange.Find.Found = True Then myRange.Text =
Selection.Characters.Count
' Stop
' Selection.Find.Execute
' 'Selection.Delete
' Stop
' MsgBox (Selection.Characters.Count)
' Selection.InsertBefore Selection.Characters.Count
' Stop
' 'Selection.Replace
Next asciipointer
End Sub Tag: how do i insert a brainstorm? Tag: 106588
Reappearance of Error 91
Strange behaviour.
I have just reinstalled Office 2003 in place of 2007, I have regained
ability to add to my custom dictionary and to Spell Check in Outlook
Express but a weird on exit error message has reappeared. Whenever I
exit from Word I get a Microsoft Visual Basic message box saying
run-time error '91': Object variable or With block variable not set. I
thought I was running Word not Visual Basic. Could somebody please tell
me how to get rid of this annoying artefact.
--
--
Wisdom and experience come with age, they say, but I wish I could
remember the darn question Tag: how do i insert a brainstorm? Tag: 106584
Embedded document's Word icon missing after closing.
Using Word 97. When I embed other Word documents in a document and
select to display them as icons, the documents open fine and allow
changes, but after closing, the Word icon is missing from the main
document. If I double-click the area where the icon previously
appeared, the embedded document reopens. But, when it closes, the icon
does not display in the main document. The placeholder is there but no
icon.
How can this problem be solved?
Thank you,
Charlie
charlie6067 Tag: how do i insert a brainstorm? Tag: 106583