Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Access
3rdpartyusrgrp
access
activexcontrol
adp.sqlserver
commandbarsui
conversion
dataaccess.pages
developers.toolkitode
devtoolkits
externaldata
forms
formscoding
gettingstarted
internet
interopoledde
macros
modulescoding
modulesdaovba
modulesdaovba.ado
multiuser
odbcclientsvr
queries
replication
reports
security
setupconfig
tablesdbdesign
  
 
date: Thu, 7 Aug 2008 12:24:51 -0700 (PDT),    group: microsoft.public.access.developers.toolkitode        back       


Move VB command from Word to msAccess   
This works great in my word normal.dot, but I need to execute it from
a msAccess module:

Sub ClickMacroButton()
Dim oFld As Field
For Each oFld In ActiveDocument.Fields
  If oFld.Type = wdFieldMacroButton Then oFld.DoClick
  oFld.Delete
Next
End Sub

I am a real beginner at VB, so please go easy on me!
Thanks.
date: Thu, 7 Aug 2008 12:24:51 -0700 (PDT)   author:   unknown

Re: Move VB command from Word to msAccess   
Assuming you want to open Word, open a document and run the code:

Const wdFieldMacroButton As Long = 51
Const wdSaveChanges As Long = -1

Dim objWord As Object
Dim objField As Object

  Set objWord = CreateObject("Word.Application")
  objWord.Documents.Open "C:\Folder\File.doc"
  For Each objField in objWord.ActiveDocument.Fields
    If objField.Type = wdFieldMacroButton Then objField.DoClick
    objField.Delete
  Next objField
  objWord.ActiveDocument.Close SaveChanges:=wdSaveChanges
  objWord.Quit
  Set objWord = Nothing

Assuming Word is already open and you want to run the code for the active 
document in it:

Const wdFieldMacroButton As Long = 51
Const wdSaveChanges As Long = -1

Dim objWord As Object
Dim objField As Object

  Set objWord = GetObject(, "Word.Application")
  For Each objField in objWord.ActiveDocument.Fields
    If objField.Type = wdFieldMacroButton Then objField.DoClick
    objField.Delete
  Next objField
  objWord.ActiveDocument.Save
  Set objWord = Nothing

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


 wrote in message 
news:6cd0c484-c579-4190-a183-9f1a0bfe122b@o40g2000prn.googlegroups.com...
> This works great in my word normal.dot, but I need to execute it from
> a msAccess module:
>
> Sub ClickMacroButton()
> Dim oFld As Field
> For Each oFld In ActiveDocument.Fields
>  If oFld.Type = wdFieldMacroButton Then oFld.DoClick
>  oFld.Delete
> Next
> End Sub
>
> I am a real beginner at VB, so please go easy on me!
> Thanks.
date: Thu, 7 Aug 2008 17:14:38 -0400   author:   Douglas J. Steele

Re: Move VB command from Word to msAccess   
On Aug 7, 2:14 pm, "Douglas J. Steele"
 wrote:
> Assuming you want to open Word, open a document and run the code:
>
> Const wdFieldMacroButton As Long = 51
> Const wdSaveChanges As Long = -1
>
> Dim objWord As Object
> Dim objField As Object
>
>   Set objWord = CreateObject("Word.Application")
>   objWord.Documents.Open "C:\Folder\File.doc"
>   For Each objField in objWord.ActiveDocument.Fields
>     If objField.Type = wdFieldMacroButton Then objField.DoClick
>     objField.Delete
>   Next objField
>   objWord.ActiveDocument.Close SaveChanges:=wdSaveChanges
>   objWord.Quit
>   Set objWord = Nothing
>
> Assuming Word is already open and you want to run the code for the active
> document in it:
>
> Const wdFieldMacroButton As Long = 51
> Const wdSaveChanges As Long = -1
>
> Dim objWord As Object
> Dim objField As Object
>
>   Set objWord = GetObject(, "Word.Application")
>   For Each objField in objWord.ActiveDocument.Fields
>     If objField.Type = wdFieldMacroButton Then objField.DoClick
>     objField.Delete
>   Next objField
>   objWord.ActiveDocument.Save
>   Set objWord = Nothing
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no private e-mails, please)
>
>  wrote in message
>
> news:6cd0c484-c579-4190-a183-9f1a0bfe122b@o40g2000prn.googlegroups.com...
>
>
>
> > This works great in my word normal.dot, but I need to execute it from
> > a msAccess module:
>
> > Sub ClickMacroButton()
> > Dim oFld As Field
> > For Each oFld In ActiveDocument.Fields
> >  If oFld.Type = wdFieldMacroButton Then oFld.DoClick
> >  oFld.Delete
> > Next
> > End Sub
>
> > I am a real beginner at VB, so please go easy on me!
> > Thanks.- Hide quoted text -
>
> - Show quoted text -

Thank you.  I made a few revisions to variable names based on code I
already had going. (I think that's what you call the descriptive word
after "Dim")  The code compiles, but the macro button doesn't execute.
I double checked: There is a {MacroButton Test} in the word doc
(inserted through Ctrl-F9) and there is a macro called Test in the
normal.dot:

Dim mergform As String
mergform = "mergform.doc"

    Dim wd As Object
    Dim wdActiveDoc As Object
    Dim wdField As Object
    Const wdFieldMacroButton As Long = 51

    Set wd = CreateObject("Word.Application")
 '   need this next line or fill in's leave word w/no toolbar:
    wd.Visible = True
    wd.Application.ScreenUpdating = False

    Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
                        False, "", "", False, "", "", 0)

    With wdActiveDoc.MailMerge
        .Destination = 0
        .Execute
    End With
    wd.Windows("mergform.doc").Activate
    wd.ActiveWindow.Close 0
    wd.Visible = False


For Each wdField In wd.ActiveDocument.Fields
If wdField.Type = wdFieldMacroButton Then wdField.DoClick
wdField.Delete
Next wdField
date: Tue, 12 Aug 2008 15:53:27 -0700 (PDT)   author:   unknown

Re: Move VB command from Word to msAccess   
Try single-stepping through the code to see whether it actually does 
anything inside the For Each wdField In wd.ActiveDocument.Fields loop.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


 wrote in message 
news:105f473f-fd96-4a74-ad22-4843d75aa69c@v1g2000pra.googlegroups.com...
> - Show quoted text -

Thank you.  I made a few revisions to variable names based on code I
already had going. (I think that's what you call the descriptive word
after "Dim")  The code compiles, but the macro button doesn't execute.
I double checked: There is a {MacroButton Test} in the word doc
(inserted through Ctrl-F9) and there is a macro called Test in the
normal.dot:

Dim mergform As String
mergform = "mergform.doc"

    Dim wd As Object
    Dim wdActiveDoc As Object
    Dim wdField As Object
    Const wdFieldMacroButton As Long = 51

    Set wd = CreateObject("Word.Application")
 '   need this next line or fill in's leave word w/no toolbar:
    wd.Visible = True
    wd.Application.ScreenUpdating = False

    Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
                        False, "", "", False, "", "", 0)

    With wdActiveDoc.MailMerge
        .Destination = 0
        .Execute
    End With
    wd.Windows("mergform.doc").Activate
    wd.ActiveWindow.Close 0
    wd.Visible = False


For Each wdField In wd.ActiveDocument.Fields
If wdField.Type = wdFieldMacroButton Then wdField.DoClick
wdField.Delete
Next wdField
date: Wed, 13 Aug 2008 19:32:00 -0400   author:   Douglas J. Steele

Re: Move VB command from Word to msAccess   
On Aug 12, 3:53 pm, slickd...@yahoo.com wrote:
> On Aug 7, 2:14 pm, "Douglas J. Steele"
>
>
>
>
>
>  wrote:
> > Assuming you want to open Word, open a document and run the code:
>
> > Const wdFieldMacroButton As Long = 51
> > Const wdSaveChanges As Long = -1
>
> > Dim objWord As Object
> > Dim objField As Object
>
> >   Set objWord = CreateObject("Word.Application")
> >   objWord.Documents.Open "C:\Folder\File.doc"
> >   For Each objField in objWord.ActiveDocument.Fields
> >     If objField.Type = wdFieldMacroButton Then objField.DoClick
> >     objField.Delete
> >   Next objField
> >   objWord.ActiveDocument.Close SaveChanges:=wdSaveChanges
> >   objWord.Quit
> >   Set objWord = Nothing
>
> > Assuming Word is already open and you want to run the code for the active
> > document in it:
>
> > Const wdFieldMacroButton As Long = 51
> > Const wdSaveChanges As Long = -1
>
> > Dim objWord As Object
> > Dim objField As Object
>
> >   Set objWord = GetObject(, "Word.Application")
> >   For Each objField in objWord.ActiveDocument.Fields
> >     If objField.Type = wdFieldMacroButton Then objField.DoClick
> >     objField.Delete
> >   Next objField
> >   objWord.ActiveDocument.Save
> >   Set objWord = Nothing
>
> > --
> > Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> > (no private e-mails, please)
>
> >  wrote in message
>
> >news:6cd0c484-c579-4190-a183-9f1a0bfe122b@o40g2000prn.googlegroups.com..> > > This works great in my word normal.dot, but I need to execute it from
> > > a msAccess module:
>
> > > Sub ClickMacroButton()
> > > Dim oFld As Field
> > > For Each oFld In ActiveDocument.Fields
> > >  If oFld.Type = wdFieldMacroButton Then oFld.DoClick
> > >  oFld.Delete
> > > Next
> > > End Sub
>
> > > I am a real beginner at VB, so please go easy on me!
> > > Thanks.- Hide quoted text -
>
> > - Show quoted text -
>
> Thank you.  I made a few revisions to variable names based on code I
> already had going. (I think that's what you call the descriptive word
> after "Dim")  The code compiles, but the macro button doesn't execute.
> I double checked: There is a {MacroButton Test} in the word doc
> (inserted through Ctrl-F9) and there is a macro called Test in the
> normal.dot:
>
> Dim mergform As String
> mergform = "mergform.doc"
>
>     Dim wd As Object
>     Dim wdActiveDoc As Object
>     Dim wdField As Object
>     Const wdFieldMacroButton As Long = 51
>
>     Set wd = CreateObject("Word.Application")
>  '   need this next line or fill in's leave word w/no toolbar:
>     wd.Visible = True
>     wd.Application.ScreenUpdating = False
>
>     Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
>                         False, "", "", False, "", "", 0)
>
>     With wdActiveDoc.MailMerge
>         .Destination = 0
>         .Execute
>     End With
>     wd.Windows("mergform.doc").Activate
>     wd.ActiveWindow.Close 0
>     wd.Visible = False
>
> For Each wdField In wd.ActiveDocument.Fields
> If wdField.Type = wdFieldMacroButton Then wdField.DoClick
> wdField.Delete
> Next wdField- Hide quoted text -
>
> - Show quoted text -

I'm not sure if I made it clear that I still need help.  I added your
code, but still it does not seem to execute:

I made a few revisions to variable names based on code I
already had going. (I think that's what you call the descriptive word
after "Dim")  The code compiles, but the macro button doesn't
execute.
I double checked: There is a {MacroButton Test} in the word doc
(inserted through Ctrl-F9) and there is a macro called Test in the
normal.dot:

Dim mergform As String
mergform = "mergform.doc"


    Dim wd As Object
    Dim wdActiveDoc As Object
    Dim wdField As Object
    Const wdFieldMacroButton As Long = 51


    Set wd = CreateObject("Word.Application")
 '   need this next line or fill in's leave word w/no toolbar:
    wd.Visible = True
    wd.Application.ScreenUpdating = False


    Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
                        False, "", "", False, "", "", 0)


    With wdActiveDoc.MailMerge
        .Destination = 0
        .Execute
    End With
    wd.Windows("mergform.doc").Activate
    wd.ActiveWindow.Close 0
    wd.Visible = False


For Each wdField In wd.ActiveDocument.Fields
If wdField.Type = wdFieldMacroButton Then wdField.DoClick
wdField.Delete
Next wdField

Thank you!
date: Fri, 15 Aug 2008 10:16:13 -0700 (PDT)   author:   unknown

Re: Move VB command from Word to msAccess   
On Aug 13, 4:32 pm, "Douglas J. Steele"
 wrote:
> Try single-stepping through the code to see whether it actually does
> anything inside the For Each wdField In wd.ActiveDocument.Fields loop.
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no private e-mails, please)
>
>  wrote in message
>
> news:105f473f-fd96-4a74-ad22-4843d75aa69c@v1g2000pra.googlegroups.com...
>
> > - Show quoted text -
>
> Thank you.  I made a few revisions to variable names based on code I
> already had going. (I think that's what you call the descriptive word
> after "Dim")  The code compiles, but the macro button doesn't execute.
> I double checked: There is a {MacroButton Test} in the word doc
> (inserted through Ctrl-F9) and there is a macro called Test in the
> normal.dot:
>
> Dim mergform As String
> mergform = "mergform.doc"
>
>     Dim wd As Object
>     Dim wdActiveDoc As Object
>     Dim wdField As Object
>     Const wdFieldMacroButton As Long = 51
>
>     Set wd = CreateObject("Word.Application")
>  '   need this next line or fill in's leave word w/no toolbar:
>     wd.Visible = True
>     wd.Application.ScreenUpdating = False
>
>     Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
>                         False, "", "", False, "", "", 0)
>
>     With wdActiveDoc.MailMerge
>         .Destination = 0
>         .Execute
>     End With
>     wd.Windows("mergform.doc").Activate
>     wd.ActiveWindow.Close 0
>     wd.Visible = False
>
> For Each wdField In wd.ActiveDocument.Fields
> If wdField.Type = wdFieldMacroButton Then wdField.DoClick
> wdField.Delete
> Next wdField

Sorry, I just noticed your comment to single step through. Sorry, how
do you single step through?
date: Wed, 20 Aug 2008 22:41:48 -0700 (PDT)   author:   unknown

Re: Move VB command from Word to msAccess   
Click in the margin to the left of the line of code

  For Each wdField In wd.ActiveDocument.Fields

That should put a dot in the margin, and highlight the row. The next time 
you run the code, execution will stop on that line. Hit the F8 key to have 
execution move to the next line.

Does execution move to the next line

  If wdField.Type = wdFieldMacroButton Then wdField.DoClick

or does it go to after the line of code

  Next wdField


-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


 wrote in message 
news:7f1fa92d-431d-463a-a8ba-1bc412224a58@b30g2000prf.googlegroups.com...
On Aug 13, 4:32 pm, "Douglas J. Steele"
 wrote:
> Try single-stepping through the code to see whether it actually does
> anything inside the For Each wdField In wd.ActiveDocument.Fields loop.
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no private e-mails, please)
>
>  wrote in message
>
> news:105f473f-fd96-4a74-ad22-4843d75aa69c@v1g2000pra.googlegroups.com...
>
> > - Show quoted text -
>
> Thank you. I made a few revisions to variable names based on code I
> already had going. (I think that's what you call the descriptive word
> after "Dim") The code compiles, but the macro button doesn't execute.
> I double checked: There is a {MacroButton Test} in the word doc
> (inserted through Ctrl-F9) and there is a macro called Test in the
> normal.dot:
>
> Dim mergform As String
> mergform = "mergform.doc"
>
> Dim wd As Object
> Dim wdActiveDoc As Object
> Dim wdField As Object
> Const wdFieldMacroButton As Long = 51
>
> Set wd = CreateObject("Word.Application")
> ' need this next line or fill in's leave word w/no toolbar:
> wd.Visible = True
> wd.Application.ScreenUpdating = False
>
> Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
> False, "", "", False, "", "", 0)
>
> With wdActiveDoc.MailMerge
> .Destination = 0
> .Execute
> End With
> wd.Windows("mergform.doc").Activate
> wd.ActiveWindow.Close 0
> wd.Visible = False
>
> For Each wdField In wd.ActiveDocument.Fields
> If wdField.Type = wdFieldMacroButton Then wdField.DoClick
> wdField.Delete
> Next wdField

Sorry, I just noticed your comment to single step through. Sorry, how
do you single step through?
date: Thu, 21 Aug 2008 16:32:32 -0400   author:   Douglas J. Steele

Re: Move VB command from Word to msAccess   
On Aug 21, 1:32 pm, "Douglas J. Steele"
 wrote:
> Click in the margin to the left of the line of code
>
>   For Each wdField In wd.ActiveDocument.Fields
>
> That should put a dot in the margin, and highlight the row. The next time
> you run the code, execution will stop on that line. Hit the F8 key to have
> execution move to the next line.
>
> Does execution move to the next line
>
>   If wdField.Type = wdFieldMacroButton Then wdField.DoClick
>
> or does it go to after the line of code
>
>   Next wdField
>
> --
> Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> (no private e-mails, please)
>
>  wrote in message
>
> news:7f1fa92d-431d-463a-a8ba-1bc412224a58@b30g2000prf.googlegroups.com...
> On Aug 13, 4:32 pm, "Douglas J. Steele"
>
>
>
>
>
>  wrote:
> > Try single-stepping through the code to see whether it actually does
> > anything inside the For Each wdField In wd.ActiveDocument.Fields loop.
>
> > --
> > Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
> > (no private e-mails, please)
>
> >  wrote in message
>
> >news:105f473f-fd96-4a74-ad22-4843d75aa69c@v1g2000pra.googlegroups.com...
>
> > > - Show quoted text -
>
> > Thank you. I made a few revisions to variable names based on code I
> > already had going. (I think that's what you call the descriptive word
> > after "Dim") The code compiles, but the macro button doesn't execute.
> > I double checked: There is a {MacroButton Test} in the word doc
> > (inserted through Ctrl-F9) and there is a macro called Test in the
> > normal.dot:
>
> > Dim mergform As String
> > mergform = "mergform.doc"
>
> > Dim wd As Object
> > Dim wdActiveDoc As Object
> > Dim wdField As Object
> > Const wdFieldMacroButton As Long = 51
>
> > Set wd = CreateObject("Word.Application")
> > ' need this next line or fill in's leave word w/no toolbar:
> > wd.Visible = True
> > wd.Application.ScreenUpdating = False
>
> > Set wdActiveDoc = wd.Documents.Open(mergform, False, False, _
> > False, "", "", False, "", "", 0)
>
> > With wdActiveDoc.MailMerge
> > .Destination = 0
> > .Execute
> > End With
> > wd.Windows("mergform.doc").Activate
> > wd.ActiveWindow.Close 0
> > wd.Visible = False
>
> > For Each wdField In wd.ActiveDocument.Fields
> > If wdField.Type = wdFieldMacroButton Then wdField.DoClick
> > wdField.Delete
> > Next wdField
>
> Sorry, I just noticed your comment to single step through. Sorry, how
> do you single step through?- Hide quoted text -
>
> - Show quoted text -

Thank you for teaching me about stepping through. It is going through
each line, not skipping any. The problem, I have found, is that the
{Macrobutton test} is incorporated in a merge file. Once the file
starts merging, the macrobutton field disappears, so it no longer
exists on the merged document.  How can I code something like this?

What happens is I have a generic MSAccess module that says to Merge
form file with data file.  I need a condition to chain a macro if it
is needed for the form file.  Could I put the macro name in a field in
the data file, then programatically say to run macro referenced in
DataField[macroname] if DataField[macroname] is not blank?  It was
easy in WordPerfect, because I could use the {ChainMacro "x"} command
in the form file, and it would execute that macro after the merge was
complete. I'm trying to find an equivalent in VB.
date: Tue, 26 Aug 2008 16:33:26 -0700 (PDT)   author:   unknown

Re: Move VB command from Word to msAccess   
While I realize that you're trying to do this from Access, because you're 
getting into the bowels of the Word Object Model, you'd probably be better 
off asking in a newsgroup related to Word, such as 
microsoft.public.word.programming

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


 wrote in message 
news:53eaf645-4816-4118-bae0-a222a5d3cc61@a8g2000prf.googlegroups.com...
> - Show quoted text -

Thank you for teaching me about stepping through. It is going through
each line, not skipping any. The problem, I have found, is that the
{Macrobutton test} is incorporated in a merge file. Once the file
starts merging, the macrobutton field disappears, so it no longer
exists on the merged document.  How can I code something like this?

What happens is I have a generic MSAccess module that says to Merge
form file with data file.  I need a condition to chain a macro if it
is needed for the form file.  Could I put the macro name in a field in
the data file, then programatically say to run macro referenced in
DataField[macroname] if DataField[macroname] is not blank?  It was
easy in WordPerfect, because I could use the {ChainMacro "x"} command
in the form file, and it would execute that macro after the merge was
complete. I'm trying to find an equivalent in VB.
date: Wed, 27 Aug 2008 16:34:22 -0400   author:   Douglas J. Steele

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us