Convert Macros for use with Mac?

T

Tony

Hi All,

I'll start by saying that I have no experience with Macs, so please be
patient with me...

I've got a Word template that we've pushed out to some of our vendors that
runs a few macros when a new document based on the template is created. Up
until this point we've only had to roll it out to vendors using PCs but now
we have a vendor in a Mac environment who can't use the template. The
vendor creates a new document from the template, is prompted to allow or
disallow macros (he allows them in this instance), and the document is
created but the macros do not run. So, I'm assuming that:

1) The vba code will not work at all
2) I need to tweak the code to work with Word for Mac

In either case, I'm not sure where to start and hope someone can point me in
the correct direction. Thanks in advance for any help you can offer.

Tony
 
C

CyberTaz

Hi Tom -

I don't have all the answers, but at least I can let you know what those who
*can* answer will need to know:)

First, if the users are running Word 2008 your first assumption is correct -
Office 2008 does NOT support any version of VBA, so the macros won't run. My
gut reaction is that this is the case here. If so, AppleScript to replace
the code may be an option. OTOH...

If they're using Word 2004 or prior your code will have to be tweaked but it
should run. Mac Office is approximately 1 version behind in VBA, so if the
code was written in a more recent version than what's used on Macs the
differences may cause it to not run at all. That's the part I can't answer
for you, but there are other regulars in the group who can.

They'll need to know Mac Word/Office versions, VBA versions and probably a
copy of the code itself.

Regards |:>)
Bob Jones
[MVP] Office:Mac
 
J

John McGhie

Hi Tony:

The fact that he is getting the Enable Macros prompt indicates that he has a
version of Mac Office that still contains the VBA Interpreter: so he is at
Word 2004 or earlier.

In Word 2008, VBA code will be silently ignored, because there is no VBA
runtime in Office 2008.

VBA in Office Mac has not advanced beyond VBA 5. So you need to dust off a
copy of Word 2000 and compile there: anything that won't compile in Word
2000, will not compile on a Mac.

The general idea is to surround the stuff that won't compile with "Hash
Defines". These are compiler directives that tell the Mac compiler to
compile a different set of statements to the PC compiler.

Syntax
#If expression Then
statements
[#ElseIf expression-n Then
[elseifstatements]]
[#Else
[elsestatements]]
#End If

For example:

#If Mac Then
.Protect Password:="", NoReset:=False, Type:=wdNoProtection
#Else
.Protect Password:="", NoReset:=False, Type:=wdNoProtection, _
UseIRM:=False, EnforceStyleLock:=True
#End If

If I were you, I would put all of your hash-defines in a separate module,
because you will have to tweak them for each new version of Mac Office and
PC Office :)

You also need to explain to your vendor that if they remove Office 2004,
your template will be instantly disabled, and there is nothing you can do
about that.

So they need to remain on Office 2004 for Mac, or install a PC :)

For more information, send me an email at (e-mail address removed) and we'll take
this offline. Note: HTML email or attachments are unlikely to survive the
spam filter :)

Cheers



Hi All,

I'll start by saying that I have no experience with Macs, so please be
patient with me...

I've got a Word template that we've pushed out to some of our vendors that
runs a few macros when a new document based on the template is created. Up
until this point we've only had to roll it out to vendors using PCs but now
we have a vendor in a Mac environment who can't use the template. The
vendor creates a new document from the template, is prompted to allow or
disallow macros (he allows them in this instance), and the document is
created but the macros do not run. So, I'm assuming that:

1) The vba code will not work at all
2) I need to tweak the code to work with Word for Mac

In either case, I'm not sure where to start and hope someone can point me in
the correct direction. Thanks in advance for any help you can offer.

Tony

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 
C

CyberTaz

Hi John -

<snip>
The fact that he is getting the Enable Macros prompt indicates that he has a
version of Mac Office that still contains the VBA Interpreter: so he is at
Word 2004 or earlier.
<snip>

Depends on the exact wording of the message - which wasn't explicitly
stated:)

Macro documents (.docm) do open directly and produce no message at all.
However, opening a .dotm or generating a new .docx based on a .dotm does,
indeed, produce a mess asking whether to "Open & Remove Macros" or simply
"Open" - even the latter case renders the macro(s) neutered, of course.

AFAIK, that message cannot be disabled, whereas the warning in 2004 can be
turned off in the Security Prefs. That's why I "leaned" in that direction:)

Regards |:>)
Bob Jones
[MVP] Office:Mac
 
J

John McGhie

Yes, you are quite correct: but the 2008 choice is "Open and Remove" or just
"Open". If you get an "Allow or Disallow" choice, you're in 2004 and it's
trying to run them :)

So I lean the other way: he's in 2004 and the wheels won't really fall off
until he decides to "upgrade" :)

Cheers


Hi John -

<snip>

<snip>

Depends on the exact wording of the message - which wasn't explicitly
stated:)

Macro documents (.docm) do open directly and produce no message at all.
However, opening a .dotm or generating a new .docx based on a .dotm does,
indeed, produce a mess asking whether to "Open & Remove Macros" or simply
"Open" - even the latter case renders the macro(s) neutered, of course.

AFAIK, that message cannot be disabled, whereas the warning in 2004 can be
turned off in the Security Prefs. That's why I "leaned" in that direction:)

Regards |:>)
Bob Jones
[MVP] Office:Mac

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 
C

CyberTaz

Then we're in total agreement whether you like it or not you old goat - we
need to have version information in order to offer accurate replies:)

Regards |:>)
Bob Jones
[MVP] Office:Mac
 
T

Tony

OK Guys, if I understand you correctly, verifying the version of Word the
user has is the first step. 2004 Or earlier & I can make something work by
tweaking the code appropriately and compiling in Word 2000. 2008 And all
bets are off.

Here's the code that's running; it's very simple but I have no idea how to
tweak it appropriately but will check out the Mac MVP site. Any suggestions
are appreciated, of course...

There are a couple of fields, each of which I'd like to prepopulate when a
new doc is open, to generate 'unique' information to identify new docs as
they come back to us.

//CODE START//

Private Sub Document_New()
On Error GoTo Err_Document_New

ActiveDocument.FormFields("txtTestDate").Result = Format(Now(),
"m/d/yy")
ActiveDocument.Bookmarks("txtTestDate").Range.Fields(1).Locked = True

ActiveDocument.FormFields("txtPoNumber").Result = "SKAR" & Format(Now(),
"HhNnSs")
ActiveDocument.Bookmarks("txtPoNumber").Range.Fields(1).Locked = True

Exit_Document_New:
Exit Sub

Err_Document_New:
MsgBox Err.Description
Resume Exit_Document_New

End Sub

//CODE END//

Thanks for the feedback and assistance. I appreciate the help.

Ciao,

Tony
 
J

John McGhie

Oh, hell, he's outed me...

I resemble that remark :)


Then we're in total agreement whether you like it or not you old goat - we
need to have version information in order to offer accurate replies:)

Regards |:>)
Bob Jones
[MVP] Office:Mac

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 
J

John McGhie

In Word 2008, there are no bets, because there is no betting shop :)

Much better: Tell the CUSTOMER to compile, in Mac Word.

1) Open your template using Word>File>Open.

2) If you double-clicked, start again.

3) Open the VBA Editor by hitting Option + F11.

4) On the Debug menu choose "Compile Project".

5) Copy any lines that go Yellow and send to ...

For the sample below: I've done it for you. There's nothing wrong with the
code you sent in Mac Word 2004, clean compile. Better than my code... :)

But I would query the use of ActiveDocument. You know damn well that is
never safe in End User Land... {Hang your head in shame!!} Return the new
document as an object and store it as a variable. Then access the document
by variable name.

Chances are he's running it on a blank document that was not created from
your template and thus it has no user forms in it :)

When crossing the yawning gulf from the Dark Side, you need to understand
that Mac Users are running on Unix. They reboot their computers only when
the electricity goes off, and they re-start Word once a month, whether it
needs it or not...

Until Office 2008, of course, which is fully Office PC compliant: it won't
run that long without blowing up :)

Cheers

OK Guys, if I understand you correctly, verifying the version of Word the
user has is the first step. 2004 Or earlier & I can make something work by
tweaking the code appropriately and compiling in Word 2000. 2008 And all
bets are off.

Here's the code that's running; it's very simple but I have no idea how to
tweak it appropriately but will check out the Mac MVP site. Any suggestions
are appreciated, of course...

There are a couple of fields, each of which I'd like to prepopulate when a
new doc is open, to generate 'unique' information to identify new docs as
they come back to us.

//CODE START//

Private Sub Document_New()
On Error GoTo Err_Document_New

ActiveDocument.FormFields("txtTestDate").Result = Format(Now(),
"m/d/yy")
ActiveDocument.Bookmarks("txtTestDate").Range.Fields(1).Locked = True

ActiveDocument.FormFields("txtPoNumber").Result = "SKAR" & Format(Now(),
"HhNnSs")
ActiveDocument.Bookmarks("txtPoNumber").Range.Fields(1).Locked = True

Exit_Document_New:
Exit Sub

Err_Document_New:
MsgBox Err.Description
Resume Exit_Document_New

End Sub

//CODE END//

Thanks for the feedback and assistance. I appreciate the help.

Ciao,

Tony

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 
T

Tony

John,

Thanks again for the reply. I'll ask them to compile on the Mac and see how
things go. I'll look at getting rid of the ActiveDocument reference, as
well.

Again, I really appreciate the help. Due to the nature of our business, we
very rarely work with Mac shops, so in a way this is good, as I'm getting a
little education...

Ciao,

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top