AutoNew Macro and Bookmarks

T

The Criminal

I've coded a macro for Mac on my Office 2003 PC, except, when the Macro is
opened on the mac, it doesn't auto run. I'm looking for any possible reason
that is?

I can release the code if some VBA debugger in here has a Mac, and would
provide feedback as to what the issue is, rest assured, its document
automation, and in no way viral coding!

I used the
Sub AutoNew()
....
tasks here involving bookmarks and text using Input Boxes

Maybe the FormatDateTime code could be the problem!!?

End Sub

Method


Is there any one prepared to do some testing and provide input back or
anyone who can spot something else obvious that may be wrong?
 
J

JE McGimpsey

The Criminal said:
I've coded a macro for Mac on my Office 2003 PC, except, when the Macro is
opened on the mac, it doesn't auto run. I'm looking for any possible reason
that is?

I can release the code if some VBA debugger in here has a Mac, and would
provide feedback as to what the issue is, rest assured, its document
automation, and in no way viral coding!

I used the
Sub AutoNew()

Are you really creating a new document by selecting the template from
the Project Gallery?

If not, you're opening the template itself, and AutoNew doesn't fire.
 
T

The Criminal

JE McGimpsey said:
Are you really creating a new document by selecting the template from
the Project Gallery?

If not, you're opening the template itself, and AutoNew doesn't fire.

That was a thought, since Mac doesn't have right click, and I don't have a
Mac at the ready to fix this!

You raised a valid point, and I am getting the person to check that out, one
point you failed to mention was where Project Gallery is located, but the
other factor that is just as important is.. Is code from Word 2003
compatible with say Word X For Mac ?

He reckons he tries to run the macro and ends up in edit view. How is that
possible?
 
J

JE McGimpsey

The Criminal said:
That was a thought, since Mac doesn't have right click, and I don't have a
Mac at the ready to fix this!

???

Macs have had right-click for years, so long as one has a two (or more)
button mouse.

If not, it's standard MacOS practice to use CTRL-click instead.

FWIW, I've been using right-click on my Macs for more than a dozen
years...
You raised a valid point, and I am getting the person to check that out, one
point you failed to mention was where Project Gallery is located,

I assumed that since you wrote "I've coded a macro for Mac" that there
was a basic familiarity with MacOffice. Project Gallery opens by default
when any MacOffice app is opened. It's also the first item on the File
menu. For more, see

http://www.microsoft.com/mac/products/office2004/using.aspx?pid=usingoffi
ce2004&type=howto&article=/mac/library/how_to_articles/office2004/of_proj
ectgallery.xml
but the other factor that is just as important is.. Is code from Word
2003 compatible with say Word X For Mac ?

Depends. All MacOffice versions use VBA 5. WinOffice 00/02/03 use VBA
6.x, which introduced a few new commands (Split, Join, Round, etc.). If
your code is compatible with Word97, it's likely compatible with
MacOffice.

Most, if not all, of the VBA6 methods can be emulated using VBA5 or the
MacScript method (which isn't available in WinOffice versions - it
allows the use of MacOS's applescripting to control other apps or
execute Unix shell scripts). I use emulated methods and conditional
compilation in my cross-platform apps when necessary.

A big exception is that ActiveX controls do not run on Macs, so if you
use ActiveX controls, you'll guarantee incompatibility. Use forms
toolbar controls instead.

There are a small number of other incompatibilities, such as the
MailMessage method not being available.

He reckons he tries to run the macro and ends up in edit view. How is that
possible?

Assuming that edit view means the Visual Basic Editor, it's possible if
there's an error in the code, if there's a method/property that isn't
recognized by the compiler, if there's a run-time error, etc. It's hard
to speculate from the information you've given.

You said you were using an AutoNew code. How is your user trying to run
the macro?
 
T

The Criminal

JE McGimpsey said:
???

Macs have had right-click for years, so long as one has a two (or more)
button mouse.

If not, it's standard MacOS practice to use CTRL-click instead.

FWIW, I've been using right-click on my Macs for more than a dozen
years...


I assumed that since you wrote "I've coded a macro for Mac" that there
was a basic familiarity with MacOffice. Project Gallery opens by default
when any MacOffice app is opened. It's also the first item on the File
menu. For more, see

http://www.microsoft.com/mac/products/office2004/using.aspx?pid=usingoffi
ce2004&type=howto&article=/mac/library/how_to_articles/office2004/of_proj
ectgallery.xml


Depends. All MacOffice versions use VBA 5. WinOffice 00/02/03 use VBA
6.x, which introduced a few new commands (Split, Join, Round, etc.). If
your code is compatible with Word97, it's likely compatible with
MacOffice.

Most, if not all, of the VBA6 methods can be emulated using VBA5 or the
MacScript method (which isn't available in WinOffice versions - it
allows the use of MacOS's applescripting to control other apps or
execute Unix shell scripts). I use emulated methods and conditional
compilation in my cross-platform apps when necessary.

A big exception is that ActiveX controls do not run on Macs, so if you
use ActiveX controls, you'll guarantee incompatibility. Use forms
toolbar controls instead.

There are a small number of other incompatibilities, such as the
MailMessage method not being available.



Assuming that edit view means the Visual Basic Editor, it's possible if
there's an error in the code, if there's a method/property that isn't
recognized by the compiler, if there's a run-time error, etc. It's hard
to speculate from the information you've given.

You said you were using an AutoNew code. How is your user trying to run
the macro?

Tools > Macros > Macros > AutoNew > Run assumably, of course, I am unable to
verify this.

I'm also pretty sure that the code itself would be compatible based on what
you have mentioned, but if you are able to test it, I would be very
greatful!

I'll paste code, so you can see for yourself how clean it is, and if you
would test it for me, that'd be a bonus!.

Never knew Mac had right click, I've always heard the joke go around:

"Name one thing you can do on a PC you can't do on a Mac"

"Right Click"

That said, you learn a few things or fifty every day!

Code for macro:

Sub AutoNew()

ContractNo = InputBox("What will this Contract Number be?", "Enter Contract
Number!")

Selection.GoTo What:=wdGoToBookmark, Name:="ContractNo1"
Selection.TypeText Text:=ContractNo
Selection.GoTo What:=wdGoToBookmark, Name:="ContractNo2"
Selection.TypeText Text:=ContractNo
Selection.GoTo What:=wdGoToBookmark, Name:="ContractNo3"
Selection.TypeText Text:=ContractNo
Selection.GoTo What:=wdGoToBookmark, Name:="ContractNo4"
Selection.TypeText Text:=ContractNo
Selection.GoTo What:=wdGoToBookmark, Name:="ContractNo5"
Selection.TypeText Text:=ContractNo


End Sub


Cheers!
 
J

JE McGimpsey

The Criminal said:
Tools > Macros > Macros > AutoNew > Run assumably, of course, I am unable to
verify this.

I'm also pretty sure that the code itself would be compatible based on what
you have mentioned, but if you are able to test it, I would be very
greatful!

The code works fine for me. Two suggestions, though:

1) Making all those selections and using TypeText is really unnecessary
and inefficient. This will do the same thing:

Public Sub AutoNew()
Dim ContractNo As Variant
Dim vBookmarks As Variant
Dim i As Long
ContractNo = InputBox( _
Prompt:="What will this Contract Number be?", _
Title:="Enter Contract Number!")
vBookmarks = Array("ContractNo1", "ContractNo2", _
"ContractNo3", "ContractNo4", "ContractNo5")
With ActiveDocument.Bookmarks
For i = LBound(vBookmarks) To UBound(vBookmarks)
.Item(vBookmarks(i)).Range.Text = ContractNo
Next i
End With
End Sub

2) Since all 5 bookmarks will contain the same value, what I would
normally do is replace ContractNo2 to ContractNo5 with Ref Fields:

{ REF ContractNo1 }

then use this code to update the one bookmark field:

Public Sub AutoNew()
Const sName As String = "ContractNo1"
Dim ContractNo As Variant
Dim rBookmark As Range
ContractNo = InputBox( _
Prompt:="What will this Contract Number be?", _
Title:="Enter Contract Number!")
With ActiveDocument
With .Bookmarks
Set rBookmark = .Item(sName).Range
rBookmark.Text = ContractNo
.Add sName, rBookmark
End With
.Fields.Update
End With
End Sub
 
T

The Criminal

JE McGimpsey said:
The code works fine for me. Two suggestions, though:

1) Making all those selections and using TypeText is really unnecessary
and inefficient. This will do the same thing:

Public Sub AutoNew()
Dim ContractNo As Variant
Dim vBookmarks As Variant
Dim i As Long
ContractNo = InputBox( _
Prompt:="What will this Contract Number be?", _
Title:="Enter Contract Number!")
vBookmarks = Array("ContractNo1", "ContractNo2", _
"ContractNo3", "ContractNo4", "ContractNo5")
With ActiveDocument.Bookmarks
For i = LBound(vBookmarks) To UBound(vBookmarks)
.Item(vBookmarks(i)).Range.Text = ContractNo
Next i
End With
End Sub

2) Since all 5 bookmarks will contain the same value, what I would
normally do is replace ContractNo2 to ContractNo5 with Ref Fields:

{ REF ContractNo1 }

then use this code to update the one bookmark field:

Public Sub AutoNew()
Const sName As String = "ContractNo1"
Dim ContractNo As Variant
Dim rBookmark As Range
ContractNo = InputBox( _
Prompt:="What will this Contract Number be?", _
Title:="Enter Contract Number!")
With ActiveDocument
With .Bookmarks
Set rBookmark = .Item(sName).Range
rBookmark.Text = ContractNo
.Add sName, rBookmark
End With
.Fields.Update
End With
End Sub

JE, your a legend, one thing I messed up on, I forgot a bookmark! Your code,
would have allowed for that cause I would manually have to add the Ref's

Anyway, what needs to happen now is:

We want to make sure that there is always 5 pages no matter what. Sometimes
adding a space will make it 6 pages for example. Whats the easiest way to do
that on the Mac?
 

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

Similar Threads


Top