Apply "Space Before 18 pt" on all the paragraph immediately following
Dear Experts,
I would like to achieve the following using Word VBA:
I would like to apply an "18 pt space before" to the paragraph
immediately following a table.
For example:
Table cell Table cell Table cell
Table cell Table cell Table cell
Table cell Table cell Table cell
Paragraph immediately following the table (spacing before: 18 pt)
The macro should loop through the document and apply this to all
occurrences.
Help is much appreciated. Thank you very much in advance. Regards,
Andreas Tag: Can I make a label blink? Tag: 115143
Apply another font to all text boxes within a canvas or to grouped
Dear Experts:
Below macro changes all text within text boxes to "arial ,bold, Size
8". So far, so good. This macro is working
a. But I also got text boxes within canvasses. How do I have to
change the code so that text boxes within canvases also get their font
changed to "Arial Bold 8"?
b. I also got grouped text boxes in my document. How do I have to
change the code so that grouped text boxes also get their font changed
to "Arial Bold 8"?
Help is much appreciated. Thank you very much in advance. Regards,
Andreas
Sub ApplyFontToTextBoxes()
Dim shp As Word.Shape
For Each shp In ActiveDocument.Shapes
With shp.TextFrame
If .HasText Then
.TextRange.Font.Name = "Arial"
.TextRange.Font.Size = 8
.TextRange.Bold = True
End If
End With
Next shp
End Sub Tag: Can I make a label blink? Tag: 115142
Reference Books
Since the GUI in Word 2007 is drastically different than that of Word 2003,
I was wondering whether there's a book that described the differences. Tag: Can I make a label blink? Tag: 115140
VBA - Word 2002 form | auto-SUM function for bookmarked table cell
I've created a protected Word 2002 form that allows users to enter data into
text fields. This form will then be printed out and turned in.
I want to SUM 2-3 table cells that are bookmarked income_1, income_2, etc...
and display the result in a TOTAL cell below the values.
I can use a Word SUM Function to SUM the bookmarked values, but I have to
update that manually. This form is for others, so I would like the SUM
function to happen automatically.
Is there VBA code to automatically SUM the values in the cells bookmarked
income_1, income_2, etc...? And display it in another cell? I thought maybe
it could be a BookMark-Change event that will fire the Macro. Or maybe I
could put a button in the form that says "Calculate" and then that would fire
the manual "update" function via VBA code.
I hope you understand what I am asking. Tag: Can I make a label blink? Tag: 115137
VBA - totally disable Enter Key in Word Form? Keypreview in Word?
FIRST, I've read the MS KB article on how to insert 4 macros into a word form
to make the enter key act as a tab, and that is not the answer I need. I
want to keep the conditional formatting in my data-entry table cells in my
Word form.
I see a lot of questions that ask this, but none that seem to ask/answer
this specific question. I want to totally disable the use of the Enter key
in my Word form, NOT try to use it as TAB.
I have created a form in Word 2002, which will be a template that users can
use to create a new form they can fill out. I am using EXACT row heights,
and the form is ready to go. However, I don't want the user to be able to
press the ENTER key in the form because it creates a new line, and I'm
working with NOVICE users, so I don't want ANYTHING to be confusing at all
(or the work won't get done!). So, I want to totally disable ENTER key use
via a Word function or VBA, so that nothing happens when they press it, maybe
just a Message-Box telling them that ENTER is disabled (they can navigate by
TAB and MOUSE).
Surely this is possible, especially in VBA code. Does Word have a
Keypreview property that I can change? Set KeyValue=0, or something? When
the doc opens, a Macro runs that disables the enter key by setting its value
to 0?
If you can help me with this, I'd appreciate it. A reading of many
discussion threads got me close to the answer, but doesn't have my
situational context. Tag: Can I make a label blink? Tag: 115136
Character Limits and Macro Spell Check
I have a document with forms in it, and there are a few sections where I have
to limit the number of characters. So I inserted a Legacy Form Field text
box and then limited the characters through properties. However, when I try
to run a spell check macro, it is spell checking all of my other form fields
(these are RichText content controls), except for this one. I tried
inserting a RichText content control into the Legacy Form Field, but that
wouldn't work either. I just need to limit the characters people are typing
in this section and then spell check. To be honest, I don't even care if
it's protected or not. I've tried this macro:
Sub SCForm()
ActiveDocument.Unprotect
Selection.WholeStory
Selection.LanguageID = wdEnglishUS
ActiveDocument.CheckSpelling
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
And this one:
Sub FormsSpellCheck()
' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="not2day"
End If
' Set the language for the document.
Selection.WholeStory
Selection.LanguageID = wdEnglishUS
' Perform Spelling/Grammar check.
If Options.CheckGrammarWithSpelling = True Then
ActiveDocument.CheckGrammar
Else
ActiveDocument.CheckSpelling
End If
' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
The same thing happens. It checks everything but the character limiting
one. I also tried the one recommended on the MVP, and I couldn't get that
one to work at all. I wasn't quite sure what to copy/paste and what to
delete from that huge section.
Thanks in advance. Tag: Can I make a label blink? Tag: 115133
Mouse Wheel
I have a user form with a multipage tab. Some of the tabs in the userform
have vertical scroll bars with a hight up to 1500. The user can use the
scroll control to move up and down. I have one user who wants to use the
wheel on the mouse to move up or down.
I cannot find any reference to the mouse wheel.
Does anyone know if this is possible? I would appreciate any help you can
offer.
Thank you,
SoCal Rick Tag: Can I make a label blink? Tag: 115132
How do I calculate time in form fields?
I have a user form that users enter the time they began a project and the
time they end a project. I need it to calculate hours and minutes. I'll
admit to being a "newbie" on fill forms, so I can use any help I can get!
Thank you! Tag: Can I make a label blink? Tag: 115128
save file wihout macros
I have a template that generates a standard letter for a user based on
inputs. The macros are used to generate the correct text given a users
input. The template works well. However, sometimes we will need to access
the document later on. I do not want the users to run the macros again. Is
there a way to strip the macros out of it and just save the file? My code
ends with:
If Response = vbYes Then
date2 = Format(Now, "MM-d-yyyy")
filetypename1 = strfilename & " " & date2
ChangeFileOpenDirectory "J:\PIH\ENGINEER\CFP\"
MsgBox filetypename1, vbOKOnly, "File name would be: "
ActiveDocument.SaveAs FileName:=filetypename1,
FileFormat:=wdFormatDocument, AddToRecentFiles:=True
End If
Any help would be appreciated! Tag: Can I make a label blink? Tag: 115123
Set Focus and Incorrect Dates
I'm having a problem with getting SetFocus to work and with 1/1/2008 being
recognized as later then 12/31/2007. I have listed the code below. (Sorry
this is so long).
It originally had a Cancel = True on the Event but I was asked to remove it.
The reason being if the txtBenefitPeriodEndDate is before the txt
BenefitPeriodBeginDate but it's the begin date that was entered incorrectly
then the user has to enter a date in the txtBenefitPeriodEndDate before it
will allow them to get back to the txtBenefitPeriodBeginDate.
The two sets of dates I have work together. They are:
txtBenefitPeriodStartDate
txtBenefitPeriodEndDate (must be later then txtBenefitPeriodStartDate)
txtHRAStartDate (must be later or equal to txtBenefitPeriodStartDate)
txtHRAEndDate (must be later then txtHRAStartDate and equal to the
txtBenefitPeriodEndDate)
Since they do work together I just want to remove the text from
txtBenefitEndDate and keep the cursor there because if it moves to
txtHRAStartDate then I get that message if I click into
txtBenefitPeriodStartDate.
Here is the code for txtBenefitPeriodEndDate and txtHRAStartDate:
Private Sub txtBenefitPeriodEndDate_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
' 5.) Benefit Period End Date must be greater then 4.)
'Benefit Period Start Date.
If txtBenefitPeriodEndDate.Value < txtBenefitPeriodStartDate.Value Then
MsgBox "The Benefit Period End Date must be" _
& vbCrLf & "after the Benefit Period Start Date."
txtBenefitPeriodEndDate = Null
txtBenefitPeriodEndDate.SetFocus
End If
End Sub
Private Sub txtHRAStartDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' 6.) HRA Start Date must be later or equal to 4.) Benefit Period Start Date
If txtHRAStartDate.Value < txtBenefitPeriodStartDate Then
MsgBox "The HRA Start Date must be later or" _
& vbCrLf & "equal to the Benefit Period Start Date"
txtHRAStartDate.Value = Null
txtHRAStartDate.SetFocus
End If
End Sub
I am just beginning to learn and am very confused why SetFocus doesn't seem
to work. It seems to work fine if I want it to go in a forward motion but if
I try to get it to stay where it is or go backwards it just doesn't work.
Also, the dates. It works if 01/01/2008 (txtBenefitPeriodEndDate) is before
01/02/2008 (txtBenefitPeriodStartDate) but not if 12/31/2007 is prior to
01/01/2008. Any help I can get is greatly appreciated. Thanks. Tag: Can I make a label blink? Tag: 115118
Word 2007 Color Scheme
I can't find a way to switch color schemes using VBA in Word 2007. I know
you can apply a theme but i only want the colour scheme. Tag: Can I make a label blink? Tag: 115115
delete line containing a certain text string
I receive files containing many lines starting with the word 'Table' and
ending with the string '== =='. These are interspersed with a few lines also
beginning with 'Table' but ending with various different strings. I want to
delete the lines endiing '== ==', leaving only the others.
Each line ends with a paragraph mark (after the strings mentioned above.)
I've tried to do this with the Help available in Word and the advice given
in this discussion group but so far failed. Can anybody help?
--
Terry Sycamore Tag: Can I make a label blink? Tag: 115102
Blind print out of pages
I am to build a template for users to use and what it is to have is a button
that prints our specific sections of text. Basically, a user locates a
heading in the document and then clicks on the button and the code in the
button has to figure out how many pages are under that heading and print
them. How would I code something like that? Tag: Can I make a label blink? Tag: 115100
HELP! Text Form Fields values disappear on print
I have a word document with over 400 text form fields. The fields are filled
in through a user control. When I print preview the document, it looks fine.
When I print it, the first thing that happens is all of the values in the
text form fields disappear. Any ideas would be greatly appreciated.
Thank you,
SoCal Rick Tag: Can I make a label blink? Tag: 115093
Filtering Columns in Word?
Hi,
Iâ??m trying to implement something similar to AutoFilter in Excel. I have
several tables in a document. Two of the columns in each table are called
â??Service Descriptionâ?? and â??Type of inspectionâ?? respectively. Since there are
only three Types of inspection, a simplified version of those two columns
could look as follows:
â??Service Descriptionâ?? â??Type of Inspectionâ??
Description1 C1
Description2 C1
Description3 HGP
Description4 HGP
Description5 MI
Description6 MI
Let's suppose that every table has something similar to what's shown above.
What I would like to accomplish is that through the click of a button or a
macrobutton field or whichever you consider is the most appropriate event
handler, every table in the document gets filtered based on the Type of
Inspection.
I was thinking about having three macrobutton fields, called "CI", "HGP" and
"MI", so that upon double-clicking "CI" for example, every table in the
document hides/unhides the appropriate rows. (i.e it only shows the rows that
correspond to a CI Inpection Type).
Is there a way to accomplish this? How can I refer to each table in a
document? and moreover, How can I select the appropriate range to hide it
based on the clicked button?
Thank you,
Juan Tag: Can I make a label blink? Tag: 115087
Word Macro for Printing Sections
Hello,
We have a form letter which is 2 pages. We do a mail merge from an
Excel sheet. The mail merge creates a new word document with all of
the form letters addressed to the different addressees. It appears
that Word turns each set of pages into a section. This is fine. We
then fax these to the addressees using our fax printer. I have created
a macro that prints each section as an individual document which then
gets faxed to the customer. The problem is the number of sections is a
variable. One week it may be 90 the next it may be 100. The macro I
created has 140 print sections in it. This works fine until the last
section. Because the macro has 140 sections the last fax has not only
the 2 pages it should have but then it back tracks and adds an
additional 2 pages until it gets to 140. So the last fax may have 80
pages in it. I need the macro to understand how many sections there is
and stop when it gets to the end.
Any advise would be great!
Thank you. Tag: Can I make a label blink? Tag: 115086
Preventing macro from copying over from template to document
I have made a template which just puts in a date range then autosaves
the file to a particular name when you close it. This create a new
document, but all the macro coding from the template file is copied
into the document. How can you set it so that the coding from the
template isn't copied into the document?
I would also prefer if the file isn't saved on close, but if the name
and location of the document is just set by the macro (so when you go
file>save it still lets you change the name and location if you want).
But i coulnd't get it to go to the right directory.
This is the code i have:
Private Function WeekStart() As Date
Dim wday As Byte
wday = Weekday(Date)
Select Case wday
Case 1
WeekStart = Date
Case 2
WeekStart = Date - 1
Case 3
WeekStart = Date - 2
Case 4
WeekStart = Date - 3
Case 5
WeekStart = Date - 4
Case 6
WeekStart = Date - 5
Case 7
WeekStart = Date - 6
End Select
End Function
Private Sub Document_Close()
Sunday = Format(WeekStart() + 7, "d")
Saturday = Format(WeekStart() + 13, "d MMM yy")
FileTitle = Sunday & " - " & Saturday & ".doc"
ActiveDocument.SaveAs "J:\Editorial\Magellan\Sickness Absence\Afghan\"
& FileTitle
End Sub
Private Sub Document_New()
Selection.GoTo What:=wdGoToBookmark, Name:="DateRange"
Selection.InsertBefore Format(WeekStart() + 7, "dddd, d MMMM")
Selection.InsertAfter " to "
Selection.InsertAfter Format(WeekStart() + 13, "dddd, d MMMM yyyy")
End Sub
Thats all in the ThisDocument module.
Thanks Tag: Can I make a label blink? Tag: 115079
How can I get the time of the last input event (key and mouse
I have done a small program in VB.NET that uses the GetLastInputInfo
function to retrieve the time of the last input event. It checks every
second and it works well in Windows XP. However, when I install the
program in VISTA it crashes.
Does anyone know how I can get the time of the last input event (key
and mouse activity) in VISTA?
Any direction and help is most appreciated!
Best regards,
Tomas :) Tag: Can I make a label blink? Tag: 115076
Selecting a paragraph
I need to add '<B>' at the beginning and '</B>' at the end of the particular
paragraph then move to the beginning of the next paragraph. The following
works if the insertion point is at the beginning of the paragraph but falls
down if not.
I have tried various key combinations to try to get to the beginning of the
paragraph but if the insertion point is already there they fall down too.
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Please help
Francis Hookham
Sub htmlBold()
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.TypeText Text:="<B>"
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="</B>"
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub Tag: Can I make a label blink? Tag: 115071
Template with Conditional Formating
I am looking to create a template or form in Word 2003 that will contain a
variable number of items each with a drop down list. For example...
Body Text
Exhibit A: Drop Down List
...
Exhibit N: Drop Down List
Body Text
The drop down list for each exhibit will be the same, but the drop down item
selected for first exhibit would be different from the next. I want a way
for the user to indicate what their last exhibit will be (any letter A-N),
lets say 'D' and then only have Exhibits A through D be available. Also,
when the template is printed then only the relevant exhibits and body text
should print. Any help would be appreciated. Tag: Can I make a label blink? Tag: 115069
Continuous Numbering of Pages Across Files
I'm trying to consecutively number pages across a large number of files that
are all in the same folder. I'm trying to use the IncludeText field tip that
Cindy Meister mentions on her website but I'm running into all sorts of
weird problems. I've had this working on a few files and then "magically"
the fields no longer work and indicate there are syntax errors. I'm talking
about in the files that were working.
Does the IncludeText method actually work? Is there a better method? I'm
using Word 2003 under Windows XP.
Thanks in advance for any help/tips.
Brian Tag: Can I make a label blink? Tag: 115066
Word 2007 Global Building Blocks
Hi,
I have put my Word 2007 autotext entries into one file as a BB.dotx
and saved it in the default startup directory as noted in file
Locations. I also create a .dotm macros file that access any custom
autotext from that BB.dotx file.
There is another program that has a template in the same folder. For
some reason when this other programs template is running I get an
error that says my BB.dotx or Macros.dotm file says it is read-only.
The .dotx and .dotm files get pushed out to the users C:/ drive and is
not on a network. If I change my Macros.dotm file to be 2003
compatible then only the bb.dotx file gives an read-only warning.
Now I noticed if I saved my BB.dotx file to the ...\Application Data
\Microsoft\Building Blocks folder, then I don't get the error
anymore. However the problem is I don't want the Building Blocks to
be in the users directory. Is there a way to change the global
location for Building Blocks or a better way of doing this?
Thank you for your time and help.
Kerri Tag: Can I make a label blink? Tag: 115060
Macro to access Outlook 2007
Hello,
Ok, so here's my issue. Do to the security settings in my office, Outlook
2007 is set up so you can not write any VBA code or create any macros. But I
have this report that is made up every morning and I have began the processes
of trying to automate this report in Word 2003, and in this doc I have
calculated fields, linked excel charts/graphs, etc... .
But a couple tables that are in this report are emailed to me every morning.
The emails come as an attachment which opens up IE and displays a table. So
what I'm trying to do(if possible), is to use VB in word to pullOut/extract
or whatever the correct terminology is and place that table into word.
Possible? Tag: Can I make a label blink? Tag: 115048
change font color macro
In Word 2003, I've written a macro to change specific parts of the text in a
document to Dark Red (RGB 128,0,0) with a Find/Replace. I tested and created
the Find/Replace first, then duplicated the actions to record the macro.
When I do the F/R manually, it works just fine; it also works while I'm
recording it. After I finish the recording and run the macro, however, it
does everything EXCEPT change the color. What am I doing wrong and how can I
fix it?
Here's the text of my macro:
' FixResumeProjectName Macro
' Macro recorded 6/25/2008 by klsigel
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "---*---"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "---"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Thanks-
Karen Tag: Can I make a label blink? Tag: 115046
Block a document from email
Hello all
I would like to know how to block a document from being emailed, for example
if it had a specific word in it - maybe in the properties. I don't really
want to lock the document and I wondered if there was a way of coding a
template to block it from email. Does anyone know if that is possible?
Thank you.
Aehan Tag: Can I make a label blink? Tag: 115045
Defining a specific range
Hi there,
I'm trying to create a macro that opens Word documents in a folder and
searches for the words "Changes due to". However, I want the search to
take place in a range that starts at the "Overview" word (in a Heading
2 style) and ends when the next Heading 2 is met.
I've done some searches on this forum, but I can't find this specific
definition of my range.
Thanks for any help.
Carlos Tag: Can I make a label blink? Tag: 115041
New Page Event
Hi,
I'm looking for a "new page" event, which insert a text box whenever user
add a new page.
Is that possible?
Thanks,
Faruk Tag: Can I make a label blink? Tag: 115033
Where else can I go for word programming support?
Can anyone recommend other venues for word programming support? I've
been stuck on an issue for a couple of weeks, and for the first time
have not found a resolution by posting here. Are there other forums or
newsgroups where it'd be appropriate to post word programming questions? Tag: Can I make a label blink? Tag: 115019
Can't enable the macros in Word - system says it is but it is NOT
Went on line, followed instructions, but my system says macros are enabled,
but I still get the most annoying message that they are disabled every time I
open a WORD document Tag: Can I make a label blink? Tag: 115016
cycle through embedded excel chart objects in code
I have a doc with several excel object charts.
Can I cycle through these in VBA and change the location of the source file
(excel file)?
I need this so the pair (word and excel file) will work even if I move them
to a different location.
Thansk.
Jesper Tag: Can I make a label blink? Tag: 115014
remove warning when updating linked excel chart-objects
I have a word-document with several charts that are linked to an excel file.
When I open the doc a warning appears asking whether I want to update the
objects.
Can I get rid of this?
Thanks.
Jesper Tag: Can I make a label blink? Tag: 115013
Insert values from Excel at Bookmarks in Word
Hi,
I have a word document (Document1) with five bookmarks. I have an
excel workbook (Workbook1) with three sheets. I want to insert values
from different cells in the excel workbook into the five bookmarks.
The values in the excel workbook are placed in different cells in the
three worksheets. What would the be the code to accomplish this?
I assume the mail-merge option is out because it requires a list. The
data here is scattered across the different worksheets.
Thanks in advance for the help.
Regards,
Raj Tag: Can I make a label blink? Tag: 115004
inserting blank line
I have a template which has a userform for the user to choose which type of
letter.
the form has a dropdown and formfield("text13")
For 2 of the types I hide the dropdown and the formfield.
For the other type when I display the dropdown and formfield, I need to
insert a blank line before my next paragrapgh.
In my macro I populate 1 text field and then need to insert the blank line:
I've tried the insertafter as seen here but to no avail.
Sub NoRefPPD()
ActiveDocument.FormFields("Para2").Result = "Enclosed, please find a copy of
the report stating that you have reached Maximum Medical Improvement from the
" & _
"above-noted injury."
ActiveDocument.Bookmarks("Text13").Range.InsertAfter (Chr(13))
End Sub
How can I insert a blank line or additional carriage return after ("Text13") ?
Thanks,
Bryan Tag: Can I make a label blink? Tag: 115002
Update Links
I have about 5 links in my Word doc all lnked to 5 different excel files.
They are set to update automattically when the document opens. But if some
one changes the excel file it does not reflect it in the document until I
update the links manually by either goin to edit/links then updating them, or
by right-clicking on each and updating them seperatley, or by opening and
closing the document.
But what I want to have is a commandButton that when clicked it updates all
the links in the document. Tag: Can I make a label blink? Tag: 114999
Calling form fields by string-name?
Dear All
The name of my form is "form1". It contains two input fields:
"field_1" and "field_2".
For both files I'd like to have the same action, done in function
"TextFieldName".
Function SetTextField(TextFieldName As String)
form1.<<Name_of_Field_n>>.Font = 0
End Function
What is the syntax to pass a string as a form-name-object?
Kind regards
Oliver
I've been trying with:
- form1("TextFieldName").font = ...
- form1.Item("TextFieldName").font = ...
- form1.Index("TextFieldName").font = ...
.. with no luck... Tag: Can I make a label blink? Tag: 114996
Inserting a Page Number in a Table in a Header
I'm trying to insert a page number field inside a table inside a header.
Basically, I want the text in Cell 1,1 to print, then Cell 1,2 should have
"Page X" in it. Here's what I have so far:
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
'Wipe out header
.Select
Selection.Delete
'Add table
.Tables.Add
Range:=ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range,
NumRows:=1, NumColumns:=2
.Tables(1).Cell(1, 1).Select
Selection.TypeText Text:="Text goes here"
.Tables(1).Cell(1, 2).Select
'Selection.TypeText Text:=
Dim rng As Range
Set rng = .Tables(1).Cell(1, 2).Range
rng.ParagraphFormat.Alignment = wdAlignParagraphRight
rng.Text = "Page "
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, wdFieldPage
Unfortunately, at that last line, I get Run-Time Error 4605: "This command
is not available."
I've narrowed it down to the fact that it's in a table. How can I fix this?
I'm working on Word 2007 12.0.6311.5000.
Thanks! Tag: Can I make a label blink? Tag: 114992
Input on how to generate charts in word from Access data
I need to automatically generate a word document that has a number charts
(approx 17).
If needed I can predefine the properties of each chart (type, axis, title
etc).
The data is in a Access database. Pulling data into a template would be fine
if possible, or anything else that works.
Could you give me some pointers as how to go about this?
Should I export data to an Excel file with predefined charts and then
automatically link these into the word document?
Or should I export values directly into word and use the Graph-object to
display the charts?
I'm very good at Access VBA, moderately good at word-vba.
Thanks for any input.
Jesper Tag: Can I make a label blink? Tag: 114985
how to pause running application
hello,
How to pause an application which is creating an word report?
i want to pause these word report generation and want to resume it after i
restarting the system. The data for word report generation is taking from MS
Access and SQL server. Tag: Can I make a label blink? Tag: 114984
Problem Inserting graph
Hi,
I use the code below which I got from here to insert a line graph, which
works. But shows a bar chart before changing to a line graph which can take
some time to change and seems to be messing things up. So I have place the
following code after it to to pause things to see if it helps.
Dim StartTime
StartTime = Timer
Do While Timer < StartTime + 60
DoEvents ' Yield to other processes.
Loop
While this does seem to help, sometimes, itâ??s a bit slow and takes a bit to
long.
Is there a way of refreshing things so that the change is immediate?
Also do I have â??diag.ChartType = xlLineâ?? in the right place?
I would like to point out I have changed it so it now takes the data from a
file and not a table.
Why does this change the num lock?
Is there anything else I shold know?
Sorry i may have to many questions in one message
Sub Test()
'You need to set a reference to "Microsoft Graph 11.0 Object Library" in
'Tools > References (VBA Editor menu bar).
'Declare some variables:
Dim o_OLE As Word.OLEFormat
Dim diag As Graph.Chart
Dim docCurrent As Document
Dim rngInsertGraph As Range
Dim docSourceData As Document
Dim tblData As Table
'Then, set the variables, like:
Set docCurrent = ActiveDocument
Set docSourceData = Application.Documents.Open("C:\My Documents\test.doc")
Set tblData = docSourceData.Tables(1)
'Inserting graph at beginning of paragraph 2 in document. _
You could use the current selection instead...
Set rngInsertGraph = docCurrent.Content.Paragraphs(2).Range
rngInsertGraph.Collapse wdCollapseStart
rngInsertGraph.InlineShapes.AddOLEObject ClassType:="MSGraph.Chart.8", _
FileName:="", LinkToFile:=False, DisplayAsIcon:=False
Set o_OLE = rngInsertGraph.Paragraphs(1).Range.InlineShapes(1).OLEFormat
o_OLE.DoVerb wdOLEVerbShow
Set diag = o_OLE.Object
'Manipulate the object like this:
With diag
diag.ChartType = xlLine
With .Application.DataSheet
'Assuming row one and column one contain headers _
which means that .Cells(1,1) is empty
'Get header from docSourceData:
.Cells(1, 2).Value = Left(tblData.Cell(1, 2).Range.Text, _
Len(tblData.Cell(1, 2).Range.Text) - 2)
.Cells(1, 3).Value = Left(tblData.Cell(1, 3).Range.Text, _
Len(tblData.Cell(1, 3).Range.Text) - 2)
.Cells(1, 4).Value = Left(tblData.Cell(1, 4).Range.Text, _
Len(tblData.Cell(1, 4).Range.Text) - 2)
.Cells(2, 1).Value = Left(tblData.Cell(2, 1).Range.Text, _
Len(tblData.Cell(2, 1).Range.Text) - 2)
' If you have more than two rows...
' .Cells(3, 1).Value = Left(tblData.Cell(3, 1).Range.Text, _
' Len(tblData.Cell(3, 1).Range.Text) - 2)
' .Cells(4, 1).Value = Left(tblData.Cell(4, 1).Range.Text, _
' Len(tblData.Cell(4, 1).Range.Text) - 1)
.Cells(2, 2).Value = Left(tblData.Cell(2, 2).Range.Text, _
Len(tblData.Cell(2, 2).Range.Text) - 2)
.Cells(2, 3).Value = Left(tblData.Cell(2, 3).Range.Text, _
Len(tblData.Cell(2, 3).Range.Text) - 2)
.Cells(2, 4).Value = Left(tblData.Cell(2, 4).Range.Text, _
Len(tblData.Cell(2, 4).Range.Text) - 2)
' If you have more than two rows...
' .Cells(3, 2).Value = Left(tblData.Cell(3, 2).Range.Text, _
' Len(tblData.Cell(3, 2).Range.Text) - 2)
' .Cells(3, 3).Value = Left(tblData.Cell(3, 3).Range.Text, _
' Len(tblData.Cell(3, 3).Range.Text) - 2)
' .Cells(3, 4).Value = Left(tblData.Cell(3, 4).Range.Text, _
' Len(tblData.Cell(3, 4).Range.Text) - 1)
'Etc.
'By default, a newly inserted chart is 4x4. _
So, if you have 3 columns and only 2 rows, delete extra stuff
.Columns(5).ClearContents
.Rows(3).ClearContents
.Rows(4).ClearContents
End With
'Sample code to manipulate the chart istself
.HasLegend = False
' .Application.PlotBy = xlColumns
' .Width = CentimetersToPoints(15)
' .PlotArea.Width = CentimetersToPoints(8)
' .Axes(xlCategory, xlPrimary).TickLabelSpacing = 10
' .Axes(xlCategory, xlPrimary).TickLabels.Orientation = 90
End With
'And do not forget to destroy the objects:
'Deactivate the graph object
diag.Application.Quit
'Clear objects
Set diag = Nothing
Set o_OLE = Nothing
SendKeys "{ESC}"
docSourceData.Close wdDoNotSaveChanges
docCurrent.Range.InsertAfter "New text inserted after chart was created."
End Sub
--
Rich...
http://www.jadwizracing.co.uk Tag: Can I make a label blink? Tag: 114983
Word 2007 DocVariable losing vbCr on File Close/Open
Hello all
I am storing data from a UserForm in a Word 2007 document in DocVariable
fields. Some docvariables are being loaded from multiline textboxes via code
like:
ActiveDocument.Variables.Add "v1", TextBox1.Text
For test data, assume I type in "a" plus ENTER plus "b" into the text box
(without the double quotes) - so my textbox contains an "a" plus a vbCrLf
plus a "b". After running the above Variables.Add line in my OK_click routine
and closing down the userform, I then run this macro to display the contents
of the docvariable (all Dim statements etc removed to keep it short):
Sub aaa()
v = ActiveDocument.Variables("v1")
For i = 1 To Len(v)
s = s & Asc(Mid(v, i, 1)) & " "
Next
MsgBox s
End Sub
As expected, this displays "97 13 10 98". If I now save the document in
native DOCX or DOCM format, close it, reopen it, and then rerun the same
macro, it will now display "97 10 98". The action of closing and re-opening
the document loses the vbCr (i.e. the ascii 13). This is NOT what happens in
earlier versions of Word. Any ideas on how to stop this? All of the
{docvariable v1} field codes in the document display correctly (i.e. show the
paragraph mark) until you close and reopen the document. After reopening the
document the "a" and the "b" will be on the same line - i.e the paragraph
mark is now missing in the document.
C'ya all
Trevor Tag: Can I make a label blink? Tag: 114977
ReProtect = Reset Forms
Help, I'm using the following code to re-protect form fields in Odd Numbered
Sections. It works great except it is also resetting the form fields. Here
is the code that I am useing. Thanks for your help.
Sub reprotect()
Dim sPassword As String
For Each oSection In ActiveDocument.Sections
'If the section's index / 2 <> 0 (odd) protection needed'
If oSection.Index Mod 2 <> 0 Then
oSection.ProtectedForForms = True
Else
'no protection needed(even)'
oSection.ProtectedForForms = False
End If
Next
If lProtected <> wdNoProtection Then
sPassword = ""
ActiveDocument.Protect Type:=lProtected, NoReset:=True, Password:=""
End If
End Sub
--
Eric the Rookie Tag: Can I make a label blink? Tag: 114971
Editing template with Image to be changed.
I have over 100 documents and I have to change a small image that needs to be
changed.
Is there a way to search a document for the first graphic Object it finds
and replace them with another one? I have some scripting that replaces text,
but I'm not 100% sure how the image part of it would work since I haven't
been able to recover the actual object name.
Thanks Tag: Can I make a label blink? Tag: 114968
Way to print out more then first page
I have a word document that has a Table of Contents that uses hyperlinks. The
user selects the article they would like to view via the TOC and is taken to
the document. from there they click on a button on the page that is to print
out the document currently in view. However some of the documents have
overflown into two or more pages. Is there a way to build a function that the
document runs prior to the user clicking on the TOC so that the function
knows the number of pages assigned to each link in the TOC. That function
then passes the number of pages to the Application.PrintOut method to assure
that all the pages are printed?
The function would have to be smart enough to figure out the pages as this
function would be embedded in a template file for further use by the users. Tag: Can I make a label blink? Tag: 114965
Macro - Subtract one day from current date
Hello,
I have been reading past posts from people who want to auto put a date in
their document that is not currentdate. I have read "WORD Date & Time
Manipulation: Tips & Techniques" document and I tried doing exactly what it
has and I am not getting any closer to my goal. So I think a macro could be
the best bet.
So what I want to do (and I am open to suggestions about how it should be
done), I want to insert a date in a field, text box or whatever works best,
and have the macro subtract one day from the current day(TODAY) so it will
show yesterday's date, in this format "d-MMMM". HELPPP!!!! Tag: Can I make a label blink? Tag: 114964
Creating a Macro that will only print the current page
I am having difficulty with this task. I am unable to record a macro that
will only print one page. I have created a faux macro and edited it to
include the following:
Public Sub PrintCurrentPage()
With Dialogs(wdDialogFilePrint)
.Range = wdPrintCurrentPage
.PrintToFile = False
.Execute
End With
End Sub
but it prints the entire document and not just the current page. Can anyone
help me with this. I am using Outlook 2003 on Windows XP.
Thanks in advance Tag: Can I make a label blink? Tag: 114957
Footer Macro in Word - Section Count
I'm trying to create a macro that can copy the information in the Footer on the first page (section one) to the rest of the footers in the remainnig sections. The macro needs to know how to count the sections and use that number to 'repeat' the copy/paste function. Does that make sense? Can anyone help?
Thanks! Tag: Can I make a label blink? Tag: 114954
Inserting Signature Boxes
Hi there,
I just wondered if there was a way of inserting a number of signature boxes
at the bottom of a letter for a mail merge we are doing?
Idealy I would like to use an input box to ask how many are required and
depending on the answer (anywhere from 2 to 5) I want it to insert this
number of "Signed................. Date................ Print
Name.............." etc. I have tried this numerous ways but im afraid my
lack of knowledge/skills has got the better of me.
Does anyone have any suggestions/ideas?
Thanks very much in advance, Tag: Can I make a label blink? Tag: 114947