Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2024, 02:01 AM
Alyb Alyb is offline Word for Mac doesn't quit Mac OS X Word for Mac doesn't quit Office 2016 for Mac
Novice
Word for Mac doesn't quit
 
Join Date: Jan 2023
Posts: 8
Alyb is on a distinguished road
Default Word for Mac doesn't quit

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
The strange thing is that Word for Mac (Microsoft® Word for Mac, Version 16.91 (24111020)) doesn't quit after running the macro. How come?

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
Reply With Quote
  #2  
Old 11-18-2024, 06:43 AM
Charles Kenyon Charles Kenyon is offline Word for Mac doesn't quit Windows 11 Word for Mac doesn't quit Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,459
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by Alyb View Post
***
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?

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.
Reply With Quote
  #3  
Old 11-19-2024, 12:37 AM
macropod's Avatar
macropod macropod is offline Word for Mac doesn't quit Windows 10 Word for Mac doesn't quit Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
More importantly, once you apply 'Filling in Forms' protection, which is required for formfields to work, your code won't work.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word for Mac doesn't quit Close file or quit application ? 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
Word for Mac doesn't quit all of my formulas quit automatically calculating chenstrap Excel 4 03-16-2016 08:04 AM
Word Crash on Quit masomenos Word 2 11-09-2010 12:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft