Need Index # of current line/para/word [cont. after delay]
Thanks for the response.
> I get the answer 27785 in a second.
For me, that's terrible. I need to display the progress of many hundreds or
even thousands of hits. Even if I only call the progress bar once every 10
hits this is still an unacceptable overhead --- and I will also get a jumpy
bar.
Thanks.
Avraham.
(Btw, greetings from Israel.)
>> same with sentences
Well, I am sure that counting sentences does not work very well on our
machines, so if paras and words take as long then they also won't work.
Maybe I will get around to trying them later.
Thanks.
Avraham.
Helmut Weber wrote:
> Hi Avi,
>
> 1 GHz, 768 MB Ram, 200 pages document,
> insertion point on the last page
>
> MsgBox ActiveDocument.Range(0, Selection.Range.End).Words.Count
>
> I get the answer 27785 in a second.
>
> Same with paragraphs, same with sentences.
>
> Processing lines is something completely different,
> they depend on e.g. pagesetup, printer, font etc.
>
> > ActiveDocument.Range(0, Selection.Range.End).Sentences.Count
>
> convoluted?
>
> How about this one, which is essentially the same.
> Just a bit easier to read, maybe.
>
> Dim rDcm As Range
> Set rDcm = ActiveDocument.Range
> rDcm.End = Selection.Range.End
> MsgBox rDcm.Words.Count
>
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP, WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de" Tag: win32 Tag: 71413
Call to U: drive from Word
Hello all
I need to create a button that calls the U: drive
How can I do it?
....
Word 2003
Windows XP PRO SP2
...
Thanks a lot.
Henry Tag: win32 Tag: 71412
To check the call of Save event on DocumentBeforeSave event
Hello All,
I want to know that when the DocumentBeforeSave event is called in Word then
is it possible to know from where the event has been fired. Is it Save, Save
As, Save As Web Page, Auto Save, etc.
I want to track from which of these functions i have recieved the call.
Thanks for help.
GS Tag: win32 Tag: 71411
How do I create a new symbol for Word 2002
I have a document in Word that I want to be able to insert a symbol, which
currently does not exist in the format dropdown box to insert a symbol. The
symbol I would like to be able to add would be a box with an x inside it.
Any ideas would be very helpful. Tag: win32 Tag: 71406
Multiple Selections in Calendar Control
Is it possible to make multiple selection within the calendar control ie.
can I allow users to use the SHIFT or CONTROL keys to select multiple days
within the calendar? (I didn't see any options for multiple selections within
control properties). Can I program for this functionality using a couple
lines of code? If so what would it look like.
Thanks in advance. Tag: win32 Tag: 71403
Loop thru doc problem
Hi,
The following code is working perfectly for me except when it hits a table.
I would like it to SKIP tables and not put the sequential number field there.
I only want it if the paragraph style is Normal and not in a table.
Right now it is placing sequential numbers in each cell of the first table.
I'm getting the following error message when it gets to the end of the first
row:
Run-time error 5251. This is not a valid action for the end of a row.
I've tried several different options to get this to work. I've been looking
at it all day and am still not getting anywhere.
Any help would be greatly appreciated.
Thanks.
jbc
*********************************************
Dim oPar As Paragraph
Dim oRng As Range
ActiveWindow.View.ShowFieldCodes = True
For Each oPar In ActiveDocument.Paragraphs
If oPar.Style = "Normal" Then
If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
oPar.Range.InsertBefore vbTab
Set oRng = oPar.Range.Duplicate
oRng.Collapse direction:=wdCollapseStart
ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldSequence,
Text:= _
"Paragraph \# ""[0000]"" \n "
oRng.Paragraphs(1).Range.Fields(1).Result.Font.Bold = True
End If
End If
Next oPar
ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.Fields.Update
************************************************* Tag: win32 Tag: 71402
VBA and numlock.
A client claims that a VBA macro is turning numlock off. I looked in the
docs and see no way for VBA to do this - tell whether numlock is on or off,
yes, but change it, no. Any ideas?
--
Peter Aitken
Remove the crap from my email address before using. Tag: win32 Tag: 71397
Documents.Open Causes Terminating Error
The following Open code generates a hard kind that terminates the application
and never gets trapped. It shows up only on Windows 2000 or Word 2000 and is
fine on XP or later (and is developed on Windows XP with Word 2003).
Dim wordApp As Word.Application
Set wordApp = New Word.Application
wordApp.Documents.Open "d:\some_file_name"
Is there a reason for this? What is the work around? Tag: win32 Tag: 71393
Run-Time Error 4608
I have been trying to finalize a document by running a macro to "cleanup"
page setup values. I want to havea header setup in the end of InchesToPoints
(.38). The document page setup is with A4 paper sizing. The code that is
giving me the run-time error is:
docWd.PageSetup.HeaderDistance = InchesToPoints(0.38)
when I get to that point in the code and hover, the value is 84.95 on the
left-hand side. Does anyone have any ideas?
Thanks. Tag: win32 Tag: 71392
Highlighting mechanism like protected documents
Hi,
I want to highlight text in a Word document, that has track changes enabled
and the highlight operation should not appear as a tracked change. For
example, when we protect a in Word 2003, Word automatically highlights the
regions of the document that is editable by different users in different
colors. This highlight does not cause any tracked change, moreover, when I
look at the properties of the range object, I do not see anything different
from a normal range without protection. And when I switch the option to view
the bookmarks, I see that the highlighted regions are surrounded by bookmark
symbols. But the range object does not contain any bookmarks. Can someone
help me out here, as to how this can be done??
Thanks and Regards,
Laks Tag: win32 Tag: 71389
Can I create a macro to transfer info from a Word doc to Access?
I created a blank form in Word to be sent out electronically and completed
before being returned to me. All the data on the Word "form" is in text
boxes, check boxes or frames. Is it possible to write a macro that would
transfer the data captured in the form to an Access database already created? Tag: win32 Tag: 71384
Create Error Message
I am working in Word 2002. I have a form with many input fields. I have a
tab order macro in the document to guide through the form. Because of the
tab macro the user cannot tab to a previous field (shift + tab), doing so
tabs them out of the current field and into the next field. I would like to
have an error message come up when the user uses the shift + tab key
combination, stating they can not tab backwards, so the user is left at the
same field they were in when they pressed shift + tab.
Thanks!
--
Jamie Tag: win32 Tag: 71383
word SDK
i have a vb program that currently creates word documents using the various
word objects available within Word.Application.
currently i have microsoft word installed on my machine. is there something
else like an SDK i could install and still use my program so i can delete
the actual word program from my computer? Tag: win32 Tag: 71382
How can I speed this up??
Hi All,
I am wits end trying to find a way to speed up this procedure. Below
is a brief description of what I am trying to do followed by my code:
---Description---
We needed a way for users to import a document into our application.
The Word doc needs to be tagged in such a way that the procedure
"knows" what tag item needs to be placed in what column in the
database. Here is an example of what an Item structure looks like:
[~Item~]
[~ItemType~]Single Answer Multiple Choice
[~ItemATID~]70-057.6.2.2
[~ItemText~]What is the best installation method to use?
[~Alternative~] Custom
[~Alternative~] Typical
[~Alternative~] Complete
[~Alternative~] Ad Server
[~Alternative~] Commerce Interchange Pipeline
[~CorrectAnswer~] Custom
[~Difficulty~]3
[~Editor~]dvdastor
[~RemediationText~]
The Typical installation option installs Commerce Server and Ad Server.
It does not install the Trey Research sample site or the SDK. The Ad
Server installation option only installs Ad Server. The custom
installation option allows you to add or subtract from the Typical
installation. The complete option installs all the components and is
not the best answer.
[~ReferenceText~]
1. Implementing a Commerce Enabled Web Site Using Microsoft SS 3.0,
Commerce E - Installing Commerce Server
- Commerce Server Installation
As you can see, the tags ([~TagName~]), determine what needs to be read
and imported. I run through the document looking for the tags and set
the tag value up as a range. I then need to do some processing on the
range to capture any HTML formatting that may be included.
If I have 20 or so Item structures like the one above in a document,
the process runs for about 5 minutes and will eventually do what I
would like. However, if the document contains, 30 or more, it takes
upwards of 40 minutes or so. Most often though, I get the dreaded,
"Message Filter indicated the application is busy" error.
----My code----
'create the app
If oWord Is Nothing Then
oWord = New Word.Application
End If
oWord.Visible = False
oWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
....
'open the document
If File.Exists(SaveLocation) Then
oDoc = oWord.Documents.Open(SaveLocation)
Else
ErrorLabel("The file does not exist. Please check the
file name and try again.")
End If
.....
'At this point, I am merely crawling through the doc looking for tags
and tag values.
'Once I obtain a range, I pass the range to this function and utilize
the return value to import into the database:
Public Function PrepareTagsforImport(ByVal rngToSearch As Word.Range)
Dim rngResult As Word.Range
Try
rngResult = oDoc.Range(start:=rngToSearch.Start,
End:=rngToSearch.Start + rngToSearch.Text.Length)
With rngResult.Find
.ClearFormatting()
.Execute(findtext:="^m", ReplaceWith:="", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Replacement.ClearFormatting()
.Replacement.Font.Bold = 0
.Replacement.Font.Italic = 0
.Replacement.Font.Underline = 0
.Replacement.Font.Subscript = 0
.Replacement.Font.Superscript = 0
.Execute(findtext:="^p", ReplaceWith:="^p",
Format:=True, Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.Text = "&"
.ClearFormatting()
.Replacement.Text = "&"
.Replacement.ClearFormatting()
.Execute(Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.Text = "<"
.ClearFormatting()
.Replacement.Text = "<"
.Replacement.ClearFormatting()
.Execute(Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.Text = ">"
.ClearFormatting()
.Replacement.Text = ">"
.Replacement.ClearFormatting()
.Execute(Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Bold = 1
.Replacement.ClearFormatting()
.Replacement.Font.Bold = 0
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<b>^&</b>",
Format:=True, Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Italic = 1
.Replacement.ClearFormatting()
.Replacement.Font.Italic = 0
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<i>^&</i>",
Format:=True, Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Underline = Word.WdUnderline.wdUnderlineSingle
.Replacement.ClearFormatting()
.Replacement.Font.Underline = 0
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<u>^&</u>",
Format:=True, Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Subscript = 1
.Replacement.ClearFormatting()
.Replacement.Font.Subscript = 0
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<sub>^&</sub>",
Format:=True, Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Superscript = 1
.Replacement.ClearFormatting()
.Replacement.Font.Superscript = 0
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<sup>^&</sup>",
Format:=True, Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Name = "Tahoma"
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
face=""Tahoma"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Name = "Courier"
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
face=""Courier"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Name = "Courier New"
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
face=""Courier New"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Name = "Verdana"
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
face=""Verdana"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Name = "Times New Roman"
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font face=""Times
New Roman"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Name = "Arial"
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
face=""Arial"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 8
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""1"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 10
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""2"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 12
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""3"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 16
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""4"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 18
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""5"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 24
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""6"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
With rngResult.Find
.ClearFormatting()
.Font.Size = 32
.Replacement.ClearFormatting()
.MatchCase = True
.Execute(findtext:="", ReplaceWith:="<font
size=""7"">^&</font>", Format:=True,
Replace:=Word.WdReplace.wdReplaceAll)
End With
Return rngResult
Catch ex As Exception
ErrorLabel(ex.Message)
End Try
End Function
------------------------
I believe my slowdown comes from this procedure having to run on most
of the ranges (I don't care about formatting on some, so I just skip
this procedure for thost ranges). With so many Finds and Replaces,
could this be my issue?
As I mentioned, it works fine with smaller docs, but with larger ones,
it takes forever... Is there any way from what you see above that I
can improve the performance of my process?
Thanks for any help you can provide. Tag: win32 Tag: 71376
Programming Re Document Save
Hi,
I'm using Word97 and have approx 100 unformatted text files in the following
directory
\\FINPC13\SHARE FIN01\NR6 Draft .rpt\
I want to open each in turn, perform identical formatting on each file and
then save the file as a word document within the same directory.
The following programming performs the first part of this routine (I think!)
Sub RunNR6()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
PathToUse = "\\FINPC13\SHARE FIN01\NR6 Draft .rpt\"
myFile = Dir$(PathToUse & "*.rpt")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
Selection.WholeStory
Selection.Font.Size = 8
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11.69)
.PageHeight = InchesToPoints(8.27)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
I am struggling with the code which will then save each file (the active
document at the time) as a fully formatted word document within the following
directory:-
\\FINPC13\SHARE FIN01\NR6 Draft .rpt\
Help gratefully appreciated.
Graham Tag: win32 Tag: 71373
Programming Query Re Document Save
Hi,
I am using MS Word 97. I have approx 100 files in the following directory
"\NR6 Draft . rpt" which are unformatted text files.I have the start of some
programming which should open each file in turn and perform identical
formatting in each file as follows:-
Sub RunNR6()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
PathToUse = "\\FINPC13\SHARE FIN01\NR6 Draft .rpt\"
myFile = Dir$(PathToUse & "*.rpt")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
Selection.WholeStory
Selection.Font.Size = 8
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11.69)
.PageHeight = InchesToPoints(8.27)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
On completion of the formatting above I would like help with the programming
which then:-
saves the active document as a fully formatted word document in the same
directory "\\FINPC13\SHARE FIN01\NR6 Draft .rpt\" before repeating the
procedure with the next "text" file in the directory.
Help gratefully appreciated.
Graham Tag: win32 Tag: 71372
Run a macro in Word from command line to open envelope window
I want to create a desktop icon that will open word and automatically open
the the "Tools | Letters and Mailings", "Envelopes and Labels" window.
I have recorded a macro that opens this window, but the window is modal so
the macro cannot be terminated until the window is closed and the code behind
the macro uses ActiveDocument.Envelope.Insert with the proper arguments to
insert the envelope.
I have also tried to use Sendkeys in the macro to send the [Alt] + "T"
(Tools), [Alt] + "e" (Letters and Mailings), [Alt] + "E" (Envelopes and
Labels) {Sendkeys "%(TeE)"} but when I run it, the current time gets inserted
into the document.
Any ideas? Tag: win32 Tag: 71371
Event Sinks
Hi,
I have a Visual Basic COM addin which is handling the "DocumentBeforeClose"
event however there is another addin on the machine which is getting this
event before my COM addin. If my COM addin sets the "Cancel" variable to TRUE
the document will close regardless.
Is there anyway to catch this event before any other addins get it?
I am using Word 2003. Tag: win32 Tag: 71364
Memory Management Question
I have some VBA code that gets run within Word in which the user clicks a
menu selection (a macro launched from a toolbar). Every time the code runs,
a collection is created and populated with freshly created instances of a
class. When the macro ends, I do not have any cleanup code to set the class
instances or the collection to nil. Will this leak memory? Tag: win32 Tag: 71361
VBA to find third decimal point?
The cells in one column of a table contain numbers separated by decimal
points. The numbers can have several points (1.2.3.4.5), or none. I would
like to go through each of these cells and truncate the number just before
the third decimal point, if it exists; if not, the number would be left
alone.
What method do I need to find the third decimal point in these strings?
Thanks.
Ed Tag: win32 Tag: 71352
Word2003 doesn't save normal.dot anymore
Hi,
In a 'normal' Word environment when I change something that affects
normal.dot - adding a menubar, change a profile- I got the question "Do you
want to save the changes in normal.dot". I do have ticked the option in
Tools, Options, Save, "Ask the user if normal.dot has to be saved".
In my situation Word doesn't ask me nothing. The changes aren't saved etc. I
now have explecitly has to open normal.dot and make the changes literal in
de normal.dot file.
Normal.dot isn't read-only, I have all rights to access normal.dot.
I have done the next thing to overcome this problem:
De-install Office 2003
Re-install Office 2003
It didn't help.
Does someone have idea what's wrong?
Regards,
Marcel Tag: win32 Tag: 71344
Grouping Option Buttons
I am creating a form that has repetitive groups of option buttons. In other
words, I have several identical groupings of options buttons.
How can I ensure that one button within each group can be selected, instead
of only one option button out of the entire form?
Thanx! Tag: win32 Tag: 71342
Inserting Logo in Header
Hi all,
I am using the following code to insert a letterhead logo into a document:
If chkLetterhead.Value = True And cmbOffices.Value = "NYLetterhead" Then
If ActiveDocument.Bookmarks.Exists("Logo") Then
Set mBmRange = ActiveDocument.Bookmarks("Logo").Range
mBmRange = "NYLetterhead"
mBmRange.InsertAutoText
ActiveDocument.Bookmarks.Add Name:="Logo", Range:=mBmRange
End If
End If
If chkLetterhead.Value = True And cmbOffices.Value = "DCLetterhead" Then
If ActiveDocument.Bookmarks.Exists("Logo") Then
Set mBmRange = ActiveDocument.Bookmarks("Logo").Range
mBmRange = "DCLetterhead"
mBmRange.InsertAutoText
ActiveDocument.Bookmarks.Add Name:="Logo", Range:=mBmRange
End If
End If
If the bookmark named "Logo" is on the first page of the document this works
just fine. However, if the bookmark is in the header, it freezes. I am
using this same code in a different template to insert a logo and it works
just fine. The only real difference between these two documents is that the
one that works is a Fax cover sheet which *DOES NOT* have Different First
Page turned on. The other two templates that use it are a Memo and Letter
which both *DO* have Different First Page turned on.
Also, I have another question regarding headers and footers. I read the
following article on the Word MVPS page about preventing users from editing
headers/footers in a document:
http://word.mvps.org/faqs/customization/ProtectWord2000PlusHeader.htm.
First, will the code from this article work in Word 2003? And if it will,
can I change the line that reads:
Case wdEvenPagesFooterStory, wdEvenPagesHeaderStory, _
wdFirstPageFooterStory, wdFirstPageHeaderStory, _
wdPrimaryFooterStory, wdPrimaryHeaderStory
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
so that only the First Page Header cannot be changed, or does it have to
protect all headers and footers? The client wants to lock the header so
that when the document is e-mailed no one can delete the firm logo from the
header.
Thanks,
Anne P. Tag: win32 Tag: 71336
How do I format O'Reilly and McDonald correctly using userforms
Using Word 2003
User complete userforms to update bookmarks within templates. Where names
and addresses are used I use ProperCase to format the entries correctly.
I cannot, however work out how to format names such as O'Reilley, McDonald,
MacIntosh, De la Taste or Banham-McGuffug etc
Please help Tag: win32 Tag: 71330
Saving document after adding custom property?
Hi All
This is my first dip into VBA, so apologies if the question is trivial.
I am wanting to add the same set of custom properties to a large number of
documents, and hoped the following code (synthesized from various examples)
would work.
The problem is that the SAVE statement does not have any effect, although
the CLOSE statement does.
If I interrupt execution before the CLOSE, I see that the custom property
has been added successfully. The debugging display before the SAVE shows a
value of TRUE for ActiveDocument.Saved.
What should I do to SAVE the document?
Thanks & regards
Derrick
(Code follows:
Public Sub AddProperty()
' Display FileOpen dialogue box to select file
If Dialogs(wdDialogFileOpen).Show = -1 Then
' OK button selected, process file
With ActiveDocument.CustomDocumentProperties
.Add Name:="MyNewProperty", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:="My new value"
' Debugging: following line displays a value of "True"
MsgBox (ActiveDocument.Saved)
ActiveDocument.Save
ActiveDocument.Close
'Also tried following option to save document
'ActiveDocument.Close SaveChanges:=wdSaveChanges
End With
End If
End Sub Tag: win32 Tag: 71328
wordObject
Iâ??m developing a windows based .net application and Iâ??m using Word object for
maintaining and printing documents.
Well, here is my problem:
I managed to do the printing stuff using the word object's property itself.
I picked the Bin Numbers of my printer and I assigned them like
wrodObject.FirstPageTray = (int) 260; (the number for "Tray 2" I got it from
DeviceCapabilities API). But still the paper is not picking from the "Tray 2"
it is taking only from "Tray 1".
But in order to solve this Issue I contacted HP Printer support team and
they said to change the "Tray Mode" to "Cassette" from "First" in "Paper
Handling Menu" of the printer itself.
Then surprisingly my code works fine!
But still I have one more problem, that at the time of giving printout if
the printer has no paper in it then it gives me error on printer.
So, I decided not to change the printer setting and I revert back the change
from "cassette" to "First" on the Paper Handling of the printer itself.
And I tried doing my tray selection from the Word Application itself (not
programmatically) there in File->Print. I can able to see "options" button in
the left corner of the "Print dialog" and by seeing the below web-site I'm
able understand that our code(word object) is trying to controlling the
settings in the "options" button's Dialog.
http://www.microsoft.com/technet/scriptcenter/topics/office/manage/wordpr.mspx
But this alone will not help us to do the job, so in the same File->Print
dialog there is one more button "Properties" in the Right Top corner. If you
click through that you can see "Paper/Quality" tab and there one more "Paper
Source" combo box is available. If I change that also to "Tray 2" I'm able to
print in "Tray 2".
But I do not know how can I control this setting programmatically?
Or Am I missing out anything in word object itself?
Can any one please help me to solve this issue?
Thanks!
Regards
Karthikeyan Tag: win32 Tag: 71327
Inserting data into text files
At work we receive a txt file with client data (comma delimited) directly
from a system. This file then needs to be used as a mail merge data source.
I am trying to write code to open this data source by first asking the user
to specify the file name (input box), and then open the file and insert
headings into the first row of the file (before client data), as these
headings are used as the mail merge headings.
Currently I am stuck on the code necessary to open the txt file and then to
insert the headings (as a string) into the file in the desired location (line
1) without deleting any of the data in it.
So basically process is
File 30060418.txt is received
User opens word template
Runs macro
Asks for file name
Headings inserted into file
Mail merge reads txt file with headings
Any help on the code would be appreciated. Tag: win32 Tag: 71326
Word document vs Outlook message
Hello,
In Outlook, there is an option that says that a user can use Microsoft
Word as create/modify a message.
Because this user have a .dot file in his startup directory, he gets
some functions that was not intend for Outlook.
How can I detect with VBA that a macro runs in a Word document and not
in an Outlook message? ThisDocument.Parent, Application.AddIns.Parent
and Application.Name always return "Microsoft Word" either if it's a
document or a message.
Thank you for your advices!
Fr=E9d=E9ric Laurent
Bonjour,
Dans Outlook, il y a une option qui indique qu'un utilisateur peut
prendre Microsoft Word pour cr=E9er/modifier un message.
Mais si l'utilisateur a un fichier .dot dans son r=E9pertoire de
d=E9marrage (r=E9p. startup), il peut ex=E9cuter des fonctions qui ne sont
pas pr=E9vues pour Outlook.
Comment puis-je d=E9tecter, avec VBA, qu'une macro s'ex=E9cute dans un
document Word et non dans un message Outlook ? ThisDocument.Parent,
Application.AddIns.Parent et Application.Name retournent toujours
"Microsoft Word" peu importe que l'on soit dans un document ou dans un
message.
Merci pour vos conseils.
Fr=E9d=E9ric Laurent Tag: win32 Tag: 71322
Template help?
Hi there, I hope you kind folks can help me.
I have a friend who's quite advanced in his use of Word templates but who
seems to have hit a block in a template he's developing. In his words:
I've created a ZIP file (http://www.davecockrum.net/ComicScript.zip)
containing the comic book script template (DOT file),
the required INI file, some brief instructions on installation and use
(originally written for beta testers), and the script for LAST STAND ON
KRYPTON, which was written with a version of this template.
As you'll see, it's more than a collection of paragraph styles and
convenience macros. It really *is* a little program for writing comic book
scripts.
Here's what has me stumped:
I need a way to insert a new story page between two extant pages. (Not a new
script page, but a new page of the comic book story. If you look at the
Superman script, you'll see what I mean.)
The code not only needs to read the number of the current page and the next
page (which is easy), it also needs to be able to process the rest of the
extant script, revising the page numbers contained in the SEQ fields for
story pages, panels, and balloons. (It was necessary to use SEQ fields
rather than any of Word's internal numbering schemes, because a comic book
script requires running three separate numbering sequences in parallel.)
My failure at getting this to work begins in the module called "New Story
Page" with the subroutine called "Tweener".
If your contacts have any idea how to make this work -- or any other
suggestions for improving the template in general
-- I'm all ears/eyes/whatever the hell organ is appropriate.
....
Can I persuade anyone to help Steve out? Thanks for your attention!
[Note that I work for Microsoft but this is non-work related.] Tag: win32 Tag: 71321
WORD TEMPLATE
I have a word template with some FILLIN fields and a table with 2 formula
fields (SUM(ABOVE)). The formula fields works fine if I check the update
fields option in TOOLS > options > Print tab. However when I print, it
prompts for all FILLIN fields again. Is there any way to write a macro to
only update the 2 formula fields that I have?
Thanks! Tag: win32 Tag: 71316
check boxes
We create a lot of forms for our workers to use. A supervisor would like us
to put all parts that the worker types in in Bold. I have been able to do
this for all parts except for checkboxes. I tried using darker fonts, larger
sizes,?? I cannot get those check boxes to print bold. Can you help??? Tag: win32 Tag: 71313
Bookmarks with the wrong name
Hi,
I've written a macro that will edit my bookmark addresses to a link in
the same document using a simple search then replace loop. The problem
is, the new addresses point to a place that doesn't exist - the place
in the file is right, but the file name itself isn't there. For
example, the link might turn out to be:
C:\Desktop\Bookmark_name
So the file isn't actually in there!
My code is:
For Each oBookmark In ActiveDocument.Bookmarks
oBookmarkName = oBookmark.Name
If InStr(1, oBookmarkName,HLinkName, vbTextCompare) = 1
Then
MsgBox oBookmarkName
ActiveDocument.Hyperlinks(i).Address =
oBookmarkName
End If
Next oBookmark
Thanks! Tag: win32 Tag: 71300
Returning the count of Find/Replace in a macro
When you do a Find/Replace from the menu, Word tells the number of replaced
occurrences. In a macro, how can I determine the number of replaced strings?
Find.Replace does not seem to have any way to return the actual count of
replacements. Any ideas?
Thanks for your help,
Charlie Tag: win32 Tag: 71299
Finding special characters inserted as Asc(40) or (63)
I need to find inserted special/symbol characters entered as "(normal text)"
and Asc(40) or (63). I have seen many great ideas and macros on the subject,
but all of them seem to assume that you know what font and/or character to
look for.
The problem is that it is not known what fonts or characters are in the
document. I have a macro that loops through all fonts to find fonts in the
document. I also have a macro that searches each character and determines
whether it is a special character and, if so, its font name. However, in a
large document (300 to 500 pages), this can take forever to examine every
character.
I am hoping that I can do a Selection.Find.Execute. I can loop thru each
font in the document to do the search. If a character does not exist, that's
OK. If there is any inserted symbol (as Asc(40/63)), Find would take me to
it and I can then find the return the symbol. Bottom line is that it is not
known what characters, if any, are in the document.
Any suggestions will be really appreciated.
Charlie Tag: win32 Tag: 71297
Word VBA MAC 2004
Hi, I have been trying to add a watch in vba (Word 2004) for the MAC and can
not find how to do this. I use the watches as my main debugging tool so I am
a little freaked out to say the least. Please if anyone knows how to track
variables and how they react throughout a program it would be appreciated.
Thank you in advance. Tag: win32 Tag: 71289
Attaching files together
Is there any way to attach a file to another file? For example, I have a form
that fills out two different templates. What I want to do is to allow the
user to select Yes in a drop-down box and that to cause another file to be
either attached or copied along with the general template. So say I have
myletter.doc and I chose "yes" in that drop-down box. Then myletter - extra
info.doc would be copied over or attached to myletter.doc. Does that make any
sense? Please advise.
Thanks,
Axe Tag: win32 Tag: 71285
Addin or Attached Template
I have code I want a lot of users to have access to, and I was going to just
make my code an addin. My question is, when is it better to use an attached
template rather than an addin? I don't care whether the users can step
through the code, but just that they have access to it. I realize I can
code for either an attached template or an addin.
So, what's the intended/best use of each?
TIA Tag: win32 Tag: 71282
Mondays are tough
This is a dumb question obviously [it's Monday] but how do I determine if my
cursor is at the last line of the document, or end of file?
Thank you so much.
--
Dr. M Tag: win32 Tag: 71276
finding all text boxes in document
I'm using a macro to find all text boxes in a document. A behavior I've
witnessed that I can't explain is that rather than finding each text box
sequentially, the order in which the macro finds each text box appears
random. For instance, the macro never processes text box #1, then #2, then #3
and so on. Instead, the order is always something like: 15, 2, 3, 4, 11, 31,
and so on.
Just wondering if anyone has an explanation for why this would happen.
The code below is the portion of the macro that's supposed to find the text
boxes:
For Each myShp In ActiveDocument.Shapes
If myShp.Type = msoTextBox Then
i = i + 1
With myShp
myShp.Select
End With
myShp.ConvertToFrame
End If
Next Tag: win32 Tag: 71272
Need Index # of current line/para/word
Hi all,
Same question as before: I need the Index # of the line/para/word of
the current selction so I know where I am after a Search.
I tried this form, as suggested:
ActiveDocument.Range(0, Selection.Range.End).Sentences=AD=AD.Count
(boy, that's convoluted - and it probably goes and counts...)
together with:
ActiveDocument.Sentences.Count (changing total)
It is way too slow.
Isn't there anything faster?
tia=20
Avraham. Tag: win32 Tag: 71266
Works in Excel but not Word?
The follwing code works in excel but not in word?
It basically checks the user name.
checks to see if user name is either "Name1" or "Name2"
If the name is either of these it lets the document be open other wise the
document closes.
Any Ideas as to why it will not work?
Private Sub Document_Open()
User = Application.UserName
Application.DisplayAlerts = False
If (User = "Name1") Or (User = "Name2") Then Beep Else Application.Quit
Application.DisplayAlerts = True
End Sub Tag: win32 Tag: 71263
Word VBA to PDF... some questions
Cross posted... WORD-PC@liverpool.ac.uk and
news:\\microsoft.public.word.vba.general
I've made a template for a client and one of the requirements is that the
user be able to click a button and automatically create four different PDF
versions of the document (one version each with a different one of three
logos and a fourth version with no logo). I've got the macro working fine
printing to the Acrobat Distiller printer driver but haven't figured out:
1. how to preset the PDF file save path (I want it to automatically save the
PDF files in c:\<client name>\Marketing sheets) and
2. how to get VBA to automatically "click" the Save button in the PDF save
dialog box.
3. keep Acrobat from popping up its own window and covering up the Word
window with the second, third and fourth Save dialog boxes.
Am I going to need to create a custom Acrobat Job Options file to deal with
these things??
Any pointers??
Thanks much.
Mike Starr
--
Mike Starr WriteStarr Information Services
Technical Writer - Online Help Developer - Technical Illustrator
Graphic Designer - Desktop Publisher - MS Office Expert
(262) 694-1028 - mike@writestarr.com - http://www.writestarr.com Tag: win32 Tag: 71261
VBA Word 2002: how to get the document sentence/word # for the current (collapsed) insertion point
Hi all,
VBA Word 2002:
Anybody know how to get the document sentence number for the current
(collapsed) insertion point?
I need to display some sort of progress of running a processing routine on a
document. I am not processing on a sentence-by-sentence basis; rather the
processing searches for highlited areas, and so when a hit is made I don't
know where I am in the document. So I need some way of getting some sort of
umber to tell me where I am. Btw, this doesn't have to be the sentence
number: this could also be Word #, Line #, Paragraph # (less good). I
couldn't find any "return index number" functions in the API.
tia
Avraham Makeler Tag: win32 Tag: 71257
VBA code for closing document is performing wrong task
Lately in my Word 97 I've been having a problem with a macro which is a
customized version of DocClose in which I do some other steps in
addition to closing the document. The code used to close the document
is
WordBasic.DocClose
I've also used ActiveDocument.Close for this.
Here's what happens. When I run this customized DocClose macro using
Ctrl+W, if the active document is an unsaved document with changes, I
get the SaveAs dialog box instead of the message saying, "Do you want to
save the changes you made to Document2? If the active document is a
saved document with unsaved changes, running the DocClose macro
automatically saves the changes and closes the document!
If I comment out all the other code in the macro, leaving only
WordBasic.DocClose or ActiveDocument.Close, the problem persists. So
the problem is definitely in those two commands.
The only way I can fix the problem is to rename the DocClose macro as
something else so that Ctrl+W. is running the built-in DocClose command
again.
I've had this macro for a long time and it never gave me trouble before.
Using WordBasic.Close always worked exactly like using the built-in
DocClose command.
Also, I re-merged the Word Data key in the Registry, but that didn't
help.
Any ideas?
Thanks,
Larry Tag: win32 Tag: 71253
Get data from a close Excel Workbook?
Hi,
Does anyone know how can i get data from a close and protect workbook with
vba in word. Any suggestion? with ADO connection of something else?
Best regards,
Pat Tag: win32 Tag: 71250
Line number function
Does anyone know how I can replicate how the line numbering function in Word
works?
When I am previewing a document, I want to have a checkbox outside of the
margin area, that does not interfere with the text and does not change the
way in which lines begin or end, similar to the way the line numbers are
displayed when you indicate that you want line numbering turned on.
Any ideas? Tag: win32 Tag: 71241
No msg box by clicking a command button on a saved Word document
I followed a VBA tutor to create a command button on a Word document.
After exiting VB editor and turning off Design Mode, I can see the
"Hello" msg box by clicking the command button.
However, after re-opening the saved Word document, clicking the command
button did not show the Hello msg box.
How to fix the problem with the 'Command Button' on the Word document?
TIA.
Jeffrey Tag: win32 Tag: 71240
Deleting Macro
I recently tried stamps.com which put a button on my word 2003 toolbar. When
I removed the software from my machine, it left this. When I try to start a
new document or close word, I get warnings about macros. I don't want to
deal with this macro warning everytime I open/close word. How do I delete
the stamps.com macro items once and for all. I found the macro area but the
delete is grayed out. Also, I accidently created a new macro while trying to
play around and delete the stamps.com one. HELP. Here is one of the items I
found in the list (Quick envelope short cut.MAIN by Pitney Boes (there are 9
entries). It says it is in all active templates and documents. Tag: win32 Tag: 71238
"Do you also want to save changes to the document template?"
Hi
I have a template that contains a custom toolbar that toggles on/off
depending on selections made.
My template runs fine, the only problem is when i try to save the document,
i get a word message asking "do you also want to save changes to the
document template?"
I have added ActiveDocument.AttachedTemplate.Saved = True but continue to
get this message.
Any ideas? Tag: win32 Tag: 71232
How to solve the error message " X (null) not a valid win32 application while
opening the MS WORD