Why Won't This Macro Work?

  • Thread starter Pausert of Nikkeldepaiin
  • Start date
P

Pausert of Nikkeldepaiin

The following macro is installed in "This Workbook." All it needs to do is
identify the user's OS. If the OS is a Mac, the window maximizes and positons
itself in a certain way. If the OS is Windows (or any non-Mac OS), it should
position the window similarly, but then also cycle through each sheet and set
the font characteristics as shown. The macro works fine when I just run it,
but, even though it's in "This Workbook" and setup as an Open event, it
doesn't do anything on a PC--it doesn't error out, it just doesn't do
anything. The macro DOES position the window correctly on a Mac, but again,
on a PC, nothing happens at all. In particular, I really need the font to set
to 8 on a PC (but not on a Mac). Does anyone have any ideas? (If I can get it
to work, my ultimate plan is to modify the Mac part to rescale the font to
10, but that's assuming I can get the rest of it to go in the first place.)

Private Sub Workbook_Open()
If Application.OperatingSystem Like "*Mac*" Then
ActiveWindow.Zoom = 100
With ActiveWindow
.Top = 1
.Left = 1
.Height = Application.UsableHeight
.Width = Application.UsableWidth
End With
Else
With ActiveWindow
.WindowState = xlNormal
.Top = 1
.Left = 1
.Height = Application.UsableHeight
.Width = Application.UsableWidth
End With
Dim S As Worksheet
For Each S In ActiveWorkbook.Worksheets
Cells.Select
With Selection.Font
.Name = "Verdana"
.Size = 8
End With
Next
Sheets(1).Activate
End If
End Sub
 
C

Chip Pearson

Is it possible that (1) macros are disabled on the PC, or (2)
Application.EnableEvents is set to False?


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

"Pausert of Nikkeldepaiin"
 
D

Don Guillett

This tested on my Vista Home Premium xl2003 all updates.

Sub opersys()
If Application.OperatingSystem Like "*Mac*" Then
MsgBox "mac"

Else

For Each ws In Worksheets
With ws.Cells.Font
.Name = "Verdana"
.Size = 8
End With
Next ws

End If
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
"Pausert of Nikkeldepaiin"
 
P

Pausert of Nikkeldepaiin

Don and Chip:

Sorry about the delay in replying. I'm at work (where I'm on a Mac) so, to
test these things, I have to email them to my wife at HER work, since she's
on a PC, so there's always kind of a "testing lag."

Anyway, I checked for Chip's idea about "enable events" being false, and
that doesn't seem to be the case. So then I tried Don's idea and put the
following macro in a new workbook.

Private Sub Workbook_Open()
If Application.OperatingSystem Like "*Mac*" Then
MsgBox "Mac"

Else

For Each ws In Worksheets
With ws.Cells.Font
..Name = "Verdana"
..Size = 30
End With
Next ws

End If
End Sub

I put this code into "This Workbook" and then opened the thing on my Mac. (I
chose 30 for the font size just to make it really obvious when it worked.)
The message box correctly popped up. Then I emailed the same workbook to my
wife. She DOESN'T get the Mac box (hurray!), but then, the font on the sheets
doesn't change, either. I verified that she's enabling macros, and indeed, I
often send her things to test for me, so I don't think it's anyting she's
accidentally doing. (She runs Windows XP there, and she's always been able to
get my macros to work just fine in the past.)

So I'm stumped. If either of you have any ideas, I'd be most appreciative. I
have a dense spreadsheet that I really need to optimize for viewing and
printing on both platforms, and I'm running out of ideas.

Pausert
 
P

Pausert of Nikkeldepaiin

Hi, Chip! I just sent off a reply to both you and Don G.--It's attached to
his response since it was the last one. Thnaks for your time!
 
D

Don Guillett

I probably won't be able to help because I don't use mac but my guess? is
that there is a compatibility issue with the mac workbook not working on
XP??. All I can tell you is that I did the macro on a pc. If you like, send
me the file and I will try on my computer to see if I get the change.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
"Pausert of Nikkeldepaiin"
 
P

Pausert of Nikkeldepaiin

Thnaks for the offer, Don. On Sunday, though, I tracked down another PC and
tried the workbook on that--and it did exactly what it's supposed to do. At
this point, I'm going to assume that there's something funky going on with my
wife's PC. Or that she's on acid or something and disabling the macros while
in some altered state.

Again, though, thanks for both your improved macro and your offer to help! I
much appreatie it!
 
D

Don Guillett

You're welcome. BTW, Your wife is getting a copy of this msg.
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
"Pausert of Nikkeldepaiin"
 

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