![]() |
#1
|
|||
|
|||
![]()
I have this macro to fill a form (an RTF document) with {FORMTEXT} fields. I found no way to access these fields directly, so this is what I came up with:
Code:
Sub FillForm() Selection.Find.ClearFormatting With Selection.Find .Text = "Comments" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveRight Unit:=wdCell Selection.TypeText Text:="No comment" Selection.MoveRight Unit:=wdCell Selection.EndKey Unit:=wdLine Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend Selection.InsertDateTime DateTimeFormat:="MMMM dd, yyyy", InsertAsField:=False Selection.MoveRight Unit:=wdCell Selection.EndKey Unit:=wdLine Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend Selection.TypeText Text:="Alyb" ActiveDocument.save Application.Quit SaveChanges:=wdDoNotSaveChanges End Sub And I have one other question: every time I change a macro, I have to grant Word for Mac access to the normal.dotm. Can this step be automated/prevented? Last edited by macropod; 11-19-2024 at 12:24 AM. Reason: Added code tags |
#2
|
|||
|
|||
![]() Quote:
If you press Ctrl+S while in the visual basic editor after you made the change, you will have saved the change and will not be asked for permission. |
#3
|
||||
|
||||
![]()
A fairly simple way to access formfields programmatically:
Code:
Sub FillForm() With ActiveDocument .FormFields(1).Result = "No comment" .FormFields(2).Result = Format(Now(), "MMMM dd, yyyy") .FormFields(3).Result = "Alyb" End With Application.Quit True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
MartinGM | Excel Programming | 1 | 09-29-2023 03:25 AM |
Help Quit Working in All Office 365 Apps | RetiredCHE | Office | 0 | 10-01-2019 06:56 PM |
The Word userform checkbox (checked/unchecked) is not saved on the Application Quit | matapagi2019 | Word VBA | 3 | 03-31-2019 02:29 AM |
![]() |
chenstrap | Excel | 4 | 03-16-2016 08:04 AM |
Word Crash on Quit | masomenos | Word | 2 | 11-09-2010 12:35 AM |