Automatically display UserForm when Word Document Opens
I have a UserForm which has pulls information from a Word
document that contains nothing but two tables of
information.
The UserForm works great, and exits gracefully, but will
not automatically display when the end user opens the word
document it is built upon. I don't want the tables to be
visible to the user, just the form. Code follows:
Private Sub ThisDocument_Document_Open()
Load UserForm1
UserForm1.Show vbModeless
End Sub
Private Sub CommandButton2_Click()
Dim Msg, Style 'set dim for message box when Exit is
pressed
Msg = "Please wait while program shuts down" ' define
message
Style = vbYesOk + vbCritical + vbDefaultButton2 '
define message response buttons
Response = MsgBox(Msg, Style) ' Display message
If True Then Unload UserForm1
Application.DisplayAlerts = False
Word.Application.Quit
End Sub
Private Sub UserForm_Initialize()
Dim MyArray() As String
RowCount = ActiveDocument.Tables(1).Rows.Count
RowCount = ActiveDocument.Tables(1).Rows.Count
ColCount = ActiveDocument.Tables(1).Columns.Count
ReDim MyArray(RowCount - 1, ColCount - 1)
For i = 1 To RowCount
For j = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(1).Cell(i, j)
'Remove the paragraph and end-of-cell markers
'as we lod the array
MyArray(i - 1, j - 1) = Left(Celldata, Len
(Celldata) - 2)
Next
Next
ListBox1.ColumnCount = ColCount
ListBox1.List() = MyArray
Dim MyArrayExternal() As String
RowCount = ActiveDocument.Tables(2).Rows.Count
RowCount = ActiveDocument.Tables(2).Rows.Count
ColCount = ActiveDocument.Tables(2).Columns.Count
ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
For m = 1 To RowCount
For n = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(2).Cell(m, n)
'Remove the paragraph and end-of-cell markers
'as we load the array
MyArrayExternal(m - 1, n - 1) = Left(Celldata,
Len(Celldata) - 2)
Next
Next
ListBox2.ColumnCount = ColCount
ListBox2.List() = MyArrayExternal
End Sub
Private Sub ListBox1_Click()
For x = 0 To ListBox1.ListCount
If ListBox1.Selected(x) = True Then
MsgBox ListBox1.List(x) & ListSeparator
& " " & " Office Symbol: " & ListSeparator
& " " & ListBox1.List(x, 1) & " Project: " &
ListBox1.List(x, 2)
End If
Next x
End Sub
Private Sub ListBox2_Click()
For x = 0 To ListBox2.ListCount
If ListBox2.Selected(x) = True Then
MsgBox ListBox2.List(x) & ListSeparator
& " " & " Office Symbol: " & ListSeparator
& " " & ListBox2.List(x, 1) & " Project: " &
ListBox2.List(x, 2)
End If
Next x
End Sub
Obviously code is rough and not fully documented yet, but
will be at end product.
How do I automatically Display a UserForm when the Word
Document is Opened?
Any ideas?
Thanks
PAM Tag: MERGEFIELD? Tag: 42439
Problems with this VBA code - please help
The code below opens a new Word doc based on a template. It generally works
fine but for some PC's delivered by Dell where they pre-installed Office XP
Professional (Word 2002) the Find code doesn't work.
Anyone any ideas why the Find would not work - the Find works on my test
PCs - including a test PC running Windows XP and Office XP Professional.
But not on these Dell delivered PC's. I can't understand why?
Code:
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Dim docspath As String ' Path to template [Template has <Address> and
<Dear> in document]
Dim StrToWord As String
StrToWord = "Angus Comber 1 The Avenue Berks"
Dim sDear As String
sDear = "Angus"
On Error Resume Next 'WordStart
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = New Word.Application
End If
If objWord Is Nothing Then
MsgBox "objWord is nothing"
Exit Sub
End If
objWord.Visible = True
' To run this code you will need to change this path to the path you save
letter.dot
docspath = "c:\program files\ioffice\ltemplat\letter.dot"
Set objWordDoc = objWord.Documents.Add(docspath, False)
' Sometime get a valid objWord object but problem creating document based on
template.
' So still need to check a valid objWordDoc created
If objWordDoc Is Nothing Then
MsgBox "Unable to create Word Document object based on template: " &
docspath & " Unable to proceed with Word creation", vbCritical, "Word Error"
Exit Sub
End If
Dim bRet As Boolean
objWordDoc.Range.Find.ClearFormatting
objWordDoc.Range.Find.Replacement.ClearFormatting
objWordDoc.Range.WholeStory
' All the Find code lines below do NOT work on Dell delivered PC's
bRet = objWordDoc.Range.Find.Execute("<Address>", False, False, False,
False, False, True, Word.wdFindContinue, False, StrToWord,
Word.wdReplaceAll)
MsgBox bRet & " returned from objWordDoc.Range.Find.Execute ..." ' returns
False with Dell Office XP Pro pre-installed PC's
bRet = objWord.Selection.Find.Execute(findtext:="<Dear>",
replacewith:="FormattedDear", Replace:=wdReplaceAll)
MsgBox bRet & " returned from objWord.Selection.Find.Execute ..."
bRet = objWordDoc.Range.Find.Execute("<Dear>", False, False, , , , , , ,
sDear, True)
MsgBox bRet & " returned from objWordDoc.Range.Find.Execute ..."
MsgBox "Just to show you that other Word automation commands work OK, Next
we will type in some text"
' TypeText works fine ALWAYS!
objWord.Selection.TypeText "This is some text here I have typed in!!"
I would really appreciate some help on this.
Angus Comber
ac@NOSPAMiteloffice.com Tag: MERGEFIELD? Tag: 42438
Macro for Paragraph
Hi All! Is there a way that I can have a macro look for
a certain word in a report, but only when it is at the
start of a line and not in the middle of a name. For
example:
I need to delete the word "MED" out of a report. It is
on multiple lines, and the number of lines varies per
report. The word "MED" can also be found in certain
words like MEDical, interMEDiate, or arMED. How do I get
the macro to only go to the start of the line
(paragraph), grab the information I need to delete, and
then move to the start of the next line (not grabing
other words)? I have posted what I have below. Thanks
in advance and have a great weekend.
Julie
Selection.Find.ClearFormatting
With Selection.Find
.Text = "MED"
.Replacement.Text = _
"
"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do
Selection.Find.Execute
If Selection.Find.Found = True Then
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter,
Count:=18, Extend:=wdExtend
Selection.TypeBackspace
Else
Exit Do
End If
Loop Tag: MERGEFIELD? Tag: 42429
Replacing VBA code on Mass
Hi people,
I have a wonderful task of replacing a line of code in a
sub routine with word document. Whats bad about that I
hear you ask, well this line of code is in over 250
documents!
Is there a way to code something that can do a find and
replace within the VB code.
Any help will be much appreciated
Thanks
Mark Tag: MERGEFIELD? Tag: 42424
Prevent BeforeClose event from running for every open document
In my project I subscribe to the BeforeClose event. If I have two or more
documents open with this macro, all the documents gets hit by the event, not
just the one I am closing, no worries there. But what I would like to do is
to only have the document that's closing to run the code in the event. Is
there a way to prevent the other documents from running the code in the
events?
/Peter Tragardh Tag: MERGEFIELD? Tag: 42423
Copying Doc Content to Email
Hi,
I have a situation where I need to copy the entire content
of a Word document to an email. The document will always
contain a bitmap. I've tried using the Content property
of the document, but this excludes the bitmap. I've also
tried using the clipboard to cut and paste the content,
but again, this excludes the bitmap. I've also tried
setting the format of the email to RichText and HTML.
Still no joy.
I don't particularly want to send the doc as an
attachment, but unless anyone can shed any light on this I
will have to.
Thanks for any help
Mark Tag: MERGEFIELD? Tag: 42416
group undo actions
Hi,
Is there a way to "group" VBA actions, so that when the
user performs undo (e.g. by pressing CTRL-Z), all the VBA
actions I have grouped are undone at once?
I would like something like the following:
----
Suppose there is some VBA command to start an undo group
(e.g. application.undo.start), then write some VBA
commands, and then close the undo group (e.g.
application.undo.end)
With my imaginary method, code could look like this:
application.undo.start
.range.delete
.range.insertafter "test"
application.undo.end
If the user now performs undo, both the delete action and
the insertion of text action would be undone at once. In
the real world, the user now has to press undo twice.
------
Of course, it doesn't work with my imaginary method, but
maybe somebody knows a way to do what i want...?
thanks
WArd Tag: MERGEFIELD? Tag: 42414
Subdirectories into a userform
I am not very familiar with userforms, but I use a lot of VBA and I'm very
thankful for a lot of help from this groups.
I have a directory with hundreds of subdirectorys. They are quite difficult
to "navigate" between.
I want to make a userform where the user can write one or more letters in a
field. I want the combo-box tol be filled (is that the same as populated?)
with all subdir that starts with that letter(s). From that combobox the user
can choose one directory and then the fileopen dialog is opened.
I'm sure this is possible. Hope someone can help me in the right direction!
Thanks!
Torstein Tag: MERGEFIELD? Tag: 42412
Insert bold text after range
Hi, I have so far the following code, being executed in a
for/next-loop:
Set oRange = objWordDoc.Range
oRange.InsertAfter "some text"
oRange.InsertAfter vbcrlf
oRange.InsertAfter vbtab & "again text" & vbcrlf
my question:
How can I set "some text" to appear in bold in the
document? (I'm using VB6 to create word documents)
Many thanks,
O.B.1. Tag: MERGEFIELD? Tag: 42411
Please Help!
Hi all,
I am trying to figure out how to write some string "as HTML" In word using
vbscript. For instance, if you copy some formatted html from IE and then do
a past in word, it shows up as Formatted HTML with the tags rendered
properly. I want to manually build an HTML string and render it to the
document so that it displays as rendered HTML and not the "<tag> text <tag>"
raw HTML.
I am stuck on this for quite some time. I am building the word document
programmatically on the client using vbscript and cannot seem to get this
last bit working. I've scoured VBA articles(I've mostly ported VBA examples
to vbscript for the project so far).
Any help GREATLY appreciated!
Thanks,
Chris Tag: MERGEFIELD? Tag: 42405
Word VBA code with Windows XP and Word 2002 works for my test PC but not customer system
I have written a VB6 program which generates a Word letter based on a
template and then runs the command below:
objWord.Selection.Find.Execute "<Address>", , , , , , , , , strToWord, True
where objWord is of type Word.Application
This works fine on Office 97, 2000 and on my Word 2002 on XP test PC.
It is funny because most of the VBA code works - ie the code to load a Word
document based on the correct template works fine. The problem is that the
<Address> text is NOT replaced with the contents of the strToWord variable.
Anyone any ideas why?
Angus Comber
angus@NOSPAMiteloffice.com
<Remove NOSPAM to email me> Tag: MERGEFIELD? Tag: 42394
Closing w/Save an Excel file from a Word macro
I have a Word macro that opens a merge document and also opens the
corresponding source file in Excel. But when the macro closes the Word
document, the Excel spreadsheet won't close until I answer the prompt for a
save. How do I get the Excel spreadsheet to close without prompting?
Thanks. Tag: MERGEFIELD? Tag: 42390
Retrieving userform info into a document
Hey, I posted this at the vba for beginners list, but I am
going to post it here just in case. Plus, I am just
putting the basics down.
This code retrieves bookmarked information and puts it in
the textbox located on a userform:
UserForm2.TextBox17.Text = source.Bookmarks
("Chapter3_1").Range
This code is in a series of userforms, but the user would
like to use this function when not using the userforms.
They would like to click a button on a toolbar and insert
the same type of information (over 100 bookmarked
sections) into any place where there cursor is located,
specifically if they forgot to insert some information
after they are finished filling out the userforms.
I am not sure how to create code that can retrieve the
same type of information into wherever there cursor is
located. Any help would be much appreciated.
Thanks,
Jason Tag: MERGEFIELD? Tag: 42388
VBA command to break links
I have a Word doc with links to Excel. Is there a way
using Word VBA to break the links to Excel? Tag: MERGEFIELD? Tag: 42387
MS Word will not send the fill color-white-to the printer
I am using a Canon BC2100 inkjet printer, with the BC21e
color Cartridge.
I am printing WordArt on colored paper.
However, I cannot get white to print as a fill in any of
my WordArt.
Whatever color the paper is that's the color that comes up
where white should be.
Can you please help?
Most appreciative,
Wayne Myers Tag: MERGEFIELD? Tag: 42381
Macro using a Loop
Hi all! I am working on creating a macro to delete
information in a report. I have a header section and
under that I have client information. I need to delete
the first 18 characters of each line for confindentiality
reasons. The number of clients varies per report, so
there is not a constant number of lines. If I only need
to delete one line, I could have the macro find a certain
word in the report, go to the start of the line to be
deleted, select the characters to be deleted, and delete
that section, but I have multiple lines. I want to do a
loop, but I am not sure how I should do this. Does
anyone have any suggestions? Thanks in advance.
Ann Tag: MERGEFIELD? Tag: 42374
Word 2000 Forms: Button Caption "&" for underscore
I have a button on a Word Form that has a caption "Close". I would like to
place the "&" character before the letter "C" in my button Caption property,
so that the letter "C" is underlined, which will allow the user to press
Alt-C for a shortcut to clicking the button.
Can someone tell me why this will not work in Word? It works fine if I use
Access to create forms. If I try this in Word, the caption of my button is
"&Close".
Am I missing something? Tag: MERGEFIELD? Tag: 42363
Making files from VBA?
Hey, I want to create a simple .bat file and a txt from a
macro. Is this possible? How can I do it?
-Thanks
Paul Tag: MERGEFIELD? Tag: 42361
ReDim
Hi.
I have the following code:
Dim stringArray(0) As String
ReDim Preserve stringArray(1)
When I try to run it, I get the following error:
Compile error:
Array already dimensioned
What is the meaning of this? I thought that ReDim is the way to
redimension an array in VBScripting? Does anyone have any thoughts on
this?
Thanks
--
Jan Eliasen, representing himself and not the company he works for. Tag: MERGEFIELD? Tag: 42360
Word 2000: Sort a Combo Box
Does anyone know how I can sort an unbound combo box using Microsoft Word
and VBA? In my Initialize function of my form, I am using the .AddItem
method to populate my combo box. The user has the ability to add new items
to the combo box. I would like to be able to sort the combo box right after
the user adds a new item to the combo box. Does anyone have any code or
ideas of how I can do this? Would the same apply for a List Box? Because I
will eventually add this functionality later, but the Combo box is 1st
priority.
Thanks. Tag: MERGEFIELD? Tag: 42358
RTF from Oracle To VB
Hi all,
Is there a way to convert RTF indications to VB/Word
from an oracle SQL-select?
This is the an example of a string returned from oracle:
"{BR2}textgoeshere{BR1}paragraph goes here{BR1}again some
text" etc etc
The oracle guy at my company says this is RTF text.
Does anyone know how to interprete this in VB, so that it
can be sent to word-document, preserving the formatting
of carrige returns etc? Thanks in advance!
Regards, O.B.1. Tag: MERGEFIELD? Tag: 42354
DocumentProperties and Safe as Webpage
Hello NG,
i save some informations in Word (2000, XP) as
CustomDocumentProperties. I did this for month without any problems, i
store strings and xml-strings this way.
Now there are some new properties, when I save as Webpage (HTML) Word
hangs (2000 and XP). If I delete a property (never mind
which)everything works fine.
My first idea was that there is a limit of customdocumentproperties
(not the 255 char limit for each property). But after some tests -
this is not the problem.
Do you have any experiences in problems saving a Word-Document as HTML
when making extensive use of customdocumentproperties?
Thanks
Alfred Tag: MERGEFIELD? Tag: 42351
Inserting at end of document
Hi all,
i'm building a document generator using VB6, however
I'm not quite used to the word object model. I was
wondering if anyone can tell me how to insert a page
break at the end of the document (there are several
annexes to be added at the end, each one starting on a
new page).
This is a part of what I've got coded so far:
------------------
Set objWordApp = New Word.Application
objWordApp.Visible = True
Set objWordDoc = objWordApp.Documents.Add
("templatepath", , , True)
For intCount = 0 to objColAnnex.Count - 1
'in a loop, I would add each text from a annex classobject
'followed by a pagebreak, or first a pagebreak and then
followed by the text, whichever is the easiest.
Next intCount
---------------------
Is there anyone who could complete the code above, within
the for-next loop? I've tried to work with the
selectionobject like this:
Set sel = objWordApp.Selection
sel.MoveRight unit:=wdStory, Count:=1
sel.InsertBreak Type:=wdPageBreak
but I keep getting errormessages (bad parameter)
Thanks for your help!
Regards,
O.B.1 Tag: MERGEFIELD? Tag: 42343
Week ending date calculation
How do I display the date of the next Saturday on any given day. If today is a
Saturday then display todays date.
Thanks in advance
Geoff Tag: MERGEFIELD? Tag: 42338
How to change an equation
hi folks,
Is there a way to change an equation using VBA in a Word documents. Thanks
in advance. Angel. Tag: MERGEFIELD? Tag: 42336
Word Macro
I have worked with VBA in Excel, but I haven't in Word.
I have a report that I imported into Word and I need to
remove some words from the top of the report. I can do a
find and delete some of the information, but the other
information varies as I import the report. What is the
best way to only select the text that I need, and delete
the rest. Note: Some of the information that I need
changes everytime I import the report. I also want to
add in a watermark, otherwise, I would import my report
into Excel. Thanks in advance and have a great day!
Julie Tag: MERGEFIELD? Tag: 42333
Word 2000: Formatting words within a Bookmark
Can anyone tell me if this can be done. With VBA code, I want to add some
text to a bookmark within my document but as I am adding the text to the
bookmark, I'd like to turn on/off Bold, add Underline, add comments, etc...
I am able to do this outside of a bookmark with the Selection method, but
wanted to know if I can do this with a bookmark.
My sample code to format the text of a selection is below, which I would
like to be able to do the same thing for a bookmark:
With Selection
.TypeText Text:="This is my first paragraph"
.TypeParagraph
.TypeText Text:="This is my 2nd paragraph. Now I will "
.Font.Bold = True
.TypeText "BOLD some words. "
.Font.Bold = False
.TypeText Text:="Bold is now turned OFF. Now, add a comment
here"
.Comments.Add Selection.Range, "This is my comment"
.TypeParagraph
.TypeText Text:="This is my 3rd paragraph."
.EndKey unit:=wdLine
End With
Is this possible to do with a bookmark? My code to select the bookmark is:
ActiveDocument.Bookmarks("myBookmark").Select
If I try the same thing using my bookmark, as I did in my above example, the
text gets put after the bookmark, not within the bookmark. And, if I rerun
my code over and over, I get repeating paragraphs, because the bookmark does
not get cleared out, since my sample text is actually in the document, not
within the bookmark. Tag: MERGEFIELD? Tag: 42329
Insert Cross-Ref to last Caption by VBA?
(This was first posted to Word.Tables, where I asked about numbering tables.
I thought it might be better suited to this group. Sorry about the
double-post.)
Thanks to the heroic efforts of Jay Freedman and Suzanne Barnhill, I now
have half a handle on Captions and Cross-References. I think it will make
things easier - but first I have to implement these in a report already
written. I'm using these for table headers, and there's about 50 or so, so
I was going to put it all in a few quick macros to avoid a lot of repeated
motions.
Everything's okay, except for getting the cross-reference to automatically
choose the last / highest-numbered caption, which would be the one I just
put in. Every time I select Insert Cross-Reference, it gives me a list.
With the macro, I don't want to manually select the Caption - it will always
(for this effort) be the Caption I just inserted.
I couldn't see anything in the Help or VBA Help that would allow me to
specify which Caption to Cross-Reference. The VBA code for
InsertCrossReference has an argument for "ReferenceItem:=", and Help tells
me to use GetCrossReferenceItems, but I can't put it together to get the
last CrossReference inserted.
Any suggestions?
Ed Tag: MERGEFIELD? Tag: 42328
Macros seperate from doc?
Hello again!
Is there a way to keep a bunch of sets of macros that all
can go with one document and bind them together
programatically as needed? Thanks!
-Paul Tag: MERGEFIELD? Tag: 42327
Form Field on Unprotected Sheet
I have this wondrous code that I want to run when ff1 is exited. The
trouble is, this sheet is not protected, so the formfield is just deleted.
Is there any similar way to "run" code when text at that location is
entered? (I hope this question is not too unclear.)
TIA Tag: MERGEFIELD? Tag: 42320
How to select a paragraph via VBA
I want to select a paragraph in my macro
I have this type of line
U:\totttot\toto\t
tu\laposte.xl
At present, I search the extension .xls, then I can select the line. (result : tu\laposte.xls
How can I select the entire paragraph
U:\totttot\toto\t
tu\laposte.xl
Macro use
Selection.MoveRight Unit:=wdCharacter, Count:=
Selection.HomeKey Unit:=wdLine, Extend:=wdExten Tag: MERGEFIELD? Tag: 42319
Find the page number that a section starts on
Hi,
Does anyone know how to find the page number that a
section starts on.
I want to list all the sections within a document and to
display the page number.
Cheers,
Steven Tag: MERGEFIELD? Tag: 42310
Memory error filling a MS Word document from MS Access
Hi,
I've got a problem with memory using MS Word..
Situation:
MS Office 2000 (fully updated)
Window w2k professional (fully updated)
I have a table on a SQL Server database.
In this table I put complete word documents as objects.
Now, I have a small vb script that copies the word object
and then pastes it in Word.
This works nice, but after a number of items, I get a
message: Not enough memory, If continuing you cannot
undo...
You can continue for a number of items, but after that
Word crashes..
I found a possible fix in the knowledge base concerning
too much edits, but this wasn't it.. I added a save
command, but I still got the problem...
Did anyone else have this problem???
Or maybe a solution??
Bye,
Sander Tag: MERGEFIELD? Tag: 42308
Macros in IE and locally ?
Hey, I have a confusion. I have this word document that I
want customers to edit through IE with the word viewer
thing and then use a menu item I add to save it back to
the server.
Problem 1: I got how to add a menu item, but when I try to
do it on the opening of the document, it gives me an error
when I call the Add() sub when I open it in IE, but when I
open it with Word through an FTP. How can I get the menu
to be there when the user opens the doc?
Problem 2: When I couldn't get the menu to make itself on
document load so I tried making a "Make Menu" macro
button. I made the button, opened the doc with IE and
double clicked it, nothing happened, then I opened the doc
(a local copy, not thru ftp) with word, and the menus were
there just like the macro ran. Then I opened it again in
IE and the menus were there. I re-traced my steps many
times and it seems like if I run the menu macro either on
my local copy on my C drive in word, or on the remote copy
on a web server, changes show up in both places on the
next time I open the document. Why does this happen?
Any help would be much appreciated, I am stumped. Thanks
-Paul Tag: MERGEFIELD? Tag: 42304
Testing for Duplex
I'm trying to use the excellent article at
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=116
to set up a duplex option on a vba controlled print utility.
It works very well, but what i'd like to know is if there is a way to test
whether the printer supports duplex or not?
The demo function works very well
Sub PrintDuplexBooklet()
Dim iDuplex As Long
iDuplex = GetDuplex 'save the current setting
SetDuplex 3 'set for vertical binding
ActiveDocument.PrintOut Background:=False
SetDuplex iDuplex 'restore the original setting
End SubI was hoping iDuplex = GetDuplex would return 0 if there was no
duplex option, but it doesn't.Can anyone advise? Tag: MERGEFIELD? Tag: 42296
regional settings' list seperator variable
Hi,
I've run into the following annoying, stupid issue:
Using VBA I want to do a search for 2 or more empty
paragraphs and replace them by one paragraph. Therefore I
use the following code:
With tDoc.Range.Find
.ClearFormatting
.Text = "^13{2,}" <----- problem
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
The line ".text = "^13{2,}"" is giving me problems
however. Because the comma is a list seperator, as defined
in my MS Windows regional settings dialog box (Start,
control panel, regional settings, numbers), it works fine
on my computer.
But a colleague has his list seperator set to ";". Thus,
Word pops up saying it is not a valid expression.
I want my program to work, regardless of the regional
settings. So i tried to find a variable or constant which
contains the list seperator character (be it ",", ";" or
whatever) and create the .text string accordingly; but I
didn't find any.
Any (other) solutions,
thanks
Ward Tag: MERGEFIELD? Tag: 42287
Finding the section number
Hello
I am new to VBA, and I am writing a Word-macro
I need a way to find the section number the cursor is in.
I found the wdActiveEndSectionNumber, but that seems to always return
"2" in my macro. And I need the full number. If I am in section 2.3.1
then I need a string with "2.3.1" in it. Is this possible?
Thanks in advance
--
Jan Eliasen, representing himself and not the company he works for. Tag: MERGEFIELD? Tag: 42286
calling functions in a global template
Hi,
How can I call a function in a global template (loaded from the startup
menu) from other document templates?
Any help is appreciated.
Raymond Tag: MERGEFIELD? Tag: 42284
Template no longer available
I have a document with an attached template. When the document is moved to a
different computer at home the template is in a different path.
The UI (Tools>Templates and AddIns) shows the original template and path.
Clicking Organizer gives the error "This document template does not exist"
so Word is aware of the original template name.
ActiveDocument.AttachedTemplate returns Normal.dot.
Is there a way of getting the orignal template name?
Regards
John Yarrall Tag: MERGEFIELD? Tag: 42276
Using ftp address in a macro
Hi All,
We are currently trying to do a document comparison by comparing the
active document with a file on an FTP site. When doing manually,
everything works great, but when when I record the action, and attempt
to use the macro, we get Run-time error '5273'. The macro takes the
following form:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 12/2/2003 by NormanJD
'
ActiveDocument.Compare Name:="ftp://1.2.3.4/Compare/test.doc"
End Sub
(IP address changed to protect the guilty)
I have tried variations such as
"ftp://username:password@1.2.3.4/Compare/text.doc" and have added the
FTP site along with username and password to the "Save as" list and in
"My Network Places" I am testing this in an environment with no
firewalls or proxies, (will add those later) but anonymous logins are
disallowed. My workstations will either be running Windows 2000 or
Windows XP with Office 2000 and all latest patches for both the O/S
and Office. I've played like crazy with IE settings, but don't think
this will help as it does wotk when I do everything manually, only the
macro fails...
Has anyone tried this or have a solution? Is this a VB/macro bug?
John Norman Tag: MERGEFIELD? Tag: 42275
Compile Error
I seem to be getting a VBA error in Office due to some
kind of conflict with my RAV AntiVirus. I can neither
Save nor Save As. The only way to save a file is to close
the window. The error message I get is ...
Microsoft Visual Basic
Compile error in hidden module. Main.
It also comes up every time I open Word or Access or
Excel.
I've tried all the suggestions from the knowledge base,
including upgrading Adobe Acrobat. HELP!
Jim Dodds
jemd@wcvt.com Tag: MERGEFIELD? Tag: 42272
Unable to delete Auto_close macro
I'm trying to advise a friend who had several viruses on his Windows 2000
machine. All that's left now is a macro in Word 2000 called Auto_Close. At
one point it appeared to be active when saving a document, but now it
doesn't appear to be doing anything. Nevertheless, the Delete option is
greyed out. How can we get rid of this?
We've studied this:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;211800 (What to do
if you have a Macro Virus),
tried starting Word with the Shift key down, and renaming Normal.dot, but
that hasn't helped. Nor is there any sign of it in the Organiser. What's
going on?
--
######################
## PH, London ##
###################### Tag: MERGEFIELD? Tag: 42267
Saving to an FTP site?
How could I save to an FTP site in VBA possibly using the
SaveAs function (I tried just stuffing an ftp url with a
default username and password in as the filename where the
path should go but it didn't work). Tag: MERGEFIELD? Tag: 42262
INCLUDETEXT, updating fields within the included text
Here is what I have:
1. document(1) has an INCLUDETEXT that drags in document(2)
2. document(2) has a bookmark
3. the bookmark of document(2) is filled with a number
from an Excel spreadsheet. When you directly open document
(2), Document_Open event goes out and gets the latest
number from the spreadsheet and puts it in the bookmark
But here's the problem:
The bookmark field is NOT updated when document(2)
is "opened" by being dragged into the INCLUDETEXT of
document(1).
I conclude from this that double-click opening a document
is not quite the same as "opening" it with an INCLUDETEXT.
Is there a VBA way to "tell" document(2) it is supposed to
update itself when it is an INCLUDETEXT?
Thank you for any assistance. Tag: MERGEFIELD? Tag: 42260
"This is not allowed in this context" - xml markup in 03
I have attached well-formed and valid schema to my document and am able to tag most of my text successfully. Why does some of the text that I tag result in an error "This is not allowed in this context". What do I need to do to fix this? Tag: MERGEFIELD? Tag: 42258
Deleting the Last Section
I'm trying to provide writers with a macro for deleting
the last (portrait) section of a document (in situations
where they decide that they want to end the document with
a landscape section). My users are not very good with
page formatting, so I'm trying to make it as easy as
possible.
I've started with a recorded macro that goes into the
header/footer of the last section, makes them same as
previous, reformats the page to landscape layout, and then
deletes the final section and the previous section break.
The recorded macro is not toggling properly between the
header and footer, and is not working too well... I'm
wondering if anyone has recommendations for reworking the
code.
Here's what I've got so far. I've manually modified the
code in the section marked (*), which is completely
incorrect:
========================================================
Sub DeleteLast()
'
' DeleteLast Macro
' Macro recorded 18.11.2003 by scott.adams
'
'Go to last page and set view
Selection.EndKey Unit:=wdStory
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
'(*)Reset headers and footers to same as previous
With Section.Headers
HeaderFooter.LinkToPrevious = True
End With
With Section.Footer
HeaderFooter.LinkToPrevious = True
'Return to main document and set last section to
landscape
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
Application.Browser.Target = wdBrowseSection
Application.Browser.Next
With Selection.PageSetup
.Orientation = wdOrientLandscape
End With
'Delete the last section
With ActiveDocument.Sections.Last.Range
.Delete
End With
'Remove the previous section break
Selection.TypeBackspace
Selection.Delete Unit:=wdCharacter, Count:=1
'Reset browse by object and return to top
Application.Browser.Target = wdBrowsePage
Selection.HomeKey Unit:=wdStory
End Sub
======================================================== Tag: MERGEFIELD? Tag: 42256
edit existing autotext entries
Using Word XP VBA or VB, how can I programmatically edit
an existing autotext entry in Normal.dot?
i.e we have an entry called Dublin which has our Dublin
office details. Our office details have now changed, so
we want to change the autotext entry in normal.dot to
reflect the new details. The only results I keep on
finding all deal with Selection.Range which we won't have
in this case.
Additionally, is there any way to manipulate/set the
range.text value?
Much appreciated,
Allan Tag: MERGEFIELD? Tag: 42255
How to copy formfield without onexit macro
Is there a way to copy a formfield without copying the
onexit macro. Currently when I copy the formfield and
paste it somewhere else using VBA it copies the text,
which is what I want, but it also copies the onexit macro,
which I don't want. Anybody know how to do this? Thx. Tag: MERGEFIELD? Tag: 42254
Hi,
How to defined MERGE FIELD(Datasourc), so it avaialbe for selection?