VBA for resizing graphics (here rather than microsoft.public.publisher)

C

Colonel Blip

FYI to folks here. Been carrying this thread on microsoft.public.publisher
but more logically belongs here.


Hello, Ed!
You wrote on Thu, 14 Oct 2004 17:41:29 +0100:

EB> You will need to use different names for your button object each time
EB> (such as cbbMyButton2, cbbChangeStuffToDifferentDimensions, cbbFooBar,
EB> etc.)

Back again. Tried adding code as indicated below (changed all cbbMyButton
entries to cbbMyButton1) however I got a compile error.

I changed the Dim back to cbbMyButton only but that didn't solve the
problem. Also deleted the Dim statement altogether since I figured I only
needed one Dim. I also tried the "Private Sub cbbMyButton1_Click(ByVal Ctrl
As Office.CommandBarButton, CancelDefault As Boolean)" as "Private Sub
cbbMyButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As
Boolean)" but that didn't help.

Guess I am not interpreting the change correctly.

Thanks,
Colonel Blip.
E-mail: (e-mail address removed)


Dim WithEvents cbbMyButton1 As Office.CommandBarButton


Private Sub cbbMyButton1_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
With ThisDocument.Selection
If Not .ShapeRange.Count = 1 Then
Beep
Else
With .ShapeRange(1)
If .Width >= .Height Then
.Width = 432
.Height = 288
Else
.Width = 288
.Height = 432
End If
End With
End If
End With
End Sub

Private Sub Document_BeforeClose(Cancel As Boolean)
On Error Resume Next
CommandBars(3).Controls("Resize selection to 6"" by 4""").Delete
End Sub

Private Sub Document_Open()
On Error Resume Next
Set cbbMyButton1 = CommandBars(3).Controls.Add(, , , , True)
cbbMyButton1.FaceId = 181
cbbMyButton1.Caption = "Resize selection to 6"" by 4"""
End Sub
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
Colonel Blip said:
Also deleted the Dim statement altogether since I figured I
only needed one Dim.

As you are creating more than one button, you need more than one button
object.

So you need one Dim for cbbMyButton1, one for cbbMyButton2, etc., separate
statements in Document_Open to initialise each, and separate subs to handle
them.
 
C

Colonel Blip

Hello, Ed!
You wrote on Fri, 15 Oct 2004 21:46:01 +0100:

EB> As you are creating more than one button, you need more than one button
EB> object.

EB> So you need one Dim for cbbMyButton1, one for cbbMyButton2, etc.,
EB> separate statements in Document_Open to initialise each, and separate
EB> subs to handle them.

Got it!! (almost). I have two different macros and they run fine, even to
the point of placing one on my custom bar. However, there is a 'quirk' in
all of this. When I open publisher, and then select a template the macro
button SPACE shows up on the command bar, however the button itself doesn't
show up until I run the mouse over the area.

The second macro doesn't show up at all until I do a Macro|Run and then a
SPACE on the bar shows up and running my mouse over it produces the button.

Further, I can not get the button for the 2nd macro to show up on the
command bar when I open the template; I have to manually run the macro which
sort of defeats the whole purpose.

Any thoughts on these.

p.s. Love Publisher but it would sure be nice if macro building etc. were
more like Word. <g>

Thanks,
Colonel Blip.
E-mail: (e-mail address removed)
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
Colonel Blip said:
Got it!! (almost). I have two different macros and they run fine,
even to the point of placing one on my custom bar. However, there is
a 'quirk' in all of this. When I open publisher, and then select a
template the macro button SPACE shows up on the command bar, however
the button itself doesn't show up until I run the mouse over the area.

I tend to look at it as the button does show up, but the button face image
does not.

It also happens over here - minimizing and re-maximizing sorted it, so this
code snipped should sort it:

Dim InitialWindowState As Integer
InitialWindowState = ThisDocument.ActiveWindow.WindowState
ThisDocument.ActiveWindow.WindowState = pbWindowStateMinimize
ThisDocument.ActiveWindow.WindowState = InitialWindowState
Further, I can not get the button for the 2nd macro to show up on the
command bar when I open the template; I have to manually run the
macro which sort of defeats the whole purpose.

Do you have a SINGLE Document_Open macro?
Do you have BOTH CommandBars("Add-ins").Add() statements in it?
p.s. Love Publisher but it would sure be nice if macro building etc.
were more like Word. <g>

Publisher has only had VBA since Publisher 2002 - Word has had VBA since
either Word for Windows 95 or Word 97 - and WordBasic since Word for Windows
Version 2.0 - so Word's VBA is a little more mature than Publisher's :)
 
C

Colonel Blip

Hello, Ed!
You wrote on Sat, 16 Oct 2004 12:57:12 +0100:

EB> Dim InitialWindowState As Integer
EB> InitialWindowState = ThisDocument.ActiveWindow.WindowState
EB> ThisDocument.ActiveWindow.WindowState = pbWindowStateMinimize
EB> ThisDocument.ActiveWindow.WindowState = InitialWindowState

EB> Do you have a SINGLE Document_Open macro?
EB> Do you have BOTH CommandBars("Add-ins").Add() statements in it?

Ed,

I wasn't sure where the new code went so I made a stab at it and I was able to compile fine but it had no impact on the problems I described. I've included my VBA code below and you'll be able to see how I've coded all of it. I probably have the minimize/initial window state code more than I need it (twice) but wasn't sure.


Thanks,
Colonel Blip.
E-mail: (e-mail address removed)

Dim WithEvents cbbMyButton As Office.CommandBarButton
Dim WithEvents cbbMyButton1 As Office.CommandBarButton
Dim InitialWindowState As Integer

'This will handle 4x6 resizing

Private Sub cbbMyButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
With ThisDocument.Selection
If Not .ShapeRange.Count = 1 Then
Beep
Else
With .ShapeRange(1)
If .Width >= .Height Then
.Width = 432
.Height = 288
Else
.Width = 288
.Height = 432
End If
End With
End If
End With
End Sub

Private Sub Document_BeforeClose(Cancel As Boolean)
On Error Resume Next
CommandBars(3).Controls("Resize selection to 6"" by 4""").Delete
End Sub

Private Sub Document_Open()
InitialWindowState = ThisDocument.ActiveWindow.WindowState
ThisDocument.ActiveWindow.WindowState = pbWindowStateMinimize
ThisDocument.ActiveWindow.WindowState = InitialWindowState

On Error Resume Next
Set cbbMyButton = CommandBars(3).Controls.Add(, , , , True)
cbbMyButton.FaceId = 181
cbbMyButton.Caption = "Resize selection to 6"" by 4"""
End Sub


'This is to handle 8x10 resizing

Private Sub cbbMyButton1_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
With ThisDocument.Selection
If Not .ShapeRange.Count = 1 Then
Beep
Else
With .ShapeRange(1)
If .Width >= .Height Then
.Width = 720
.Height = 576
Else
.Width = 576
.Height = 720
End If
End With
End If
End With
End Sub

Private Sub Document_BeforeClose1(Cancel As Boolean)
On Error Resume Next
CommandBars("WLO Custom").Controls("Resize selection to 10"" by 8""").Delete
End Sub

Private Sub Document_Open1()
InitialWindowState = ThisDocument.ActiveWindow.WindowState
ThisDocument.ActiveWindow.WindowState = pbWindowStateMinimize
ThisDocument.ActiveWindow.WindowState = InitialWindowState
On Error Resume Next
Set cbbMyButton1 = CommandBars("WLO Custom").Controls.Add(, , , , True)
cbbMyButton1.FaceId = 185
cbbMyButton1.Caption = "Resize selection to 10"" by 8"""
End Sub
 
E

Ed Bennett

Ed looks left. Ed looks right. No-one is there. Furtively, Ed picks up
a note from Colonel Blip said:
I wasn't sure where the new code went so I made a stab at it and I
was able to compile fine but it had no impact on the problems I
described. I've included my VBA code below and you'll be able to see
how I've coded all of it. I probably have the minimize/initial window
state code more than I need it (twice) but wasn't sure.

The Document_Open subroutine is called when the publication is opened.
Document_Open1 is not (as it does not handle an event).
Cut and paste the code from Document_Open1 into the end of Document_Open.
Ditto that for Document_BeforeClose.

Now, if you notice, when the ghost button is added, minimizing and restoring
the window makes it appear. It will not make it appear until the button has
been added in code.

The code I wrote just minimizes and restores the window. So the code needs
to be added (only once - it will appear twice if you do the copy and paste
suggested above) AFTER the code to create the buttons, as we want the
buttons to be created, then to minimize and restore the window.
 
C

Colonel Blip

Hello, Ed!
You wrote on Sun, 17 Oct 2004 14:26:40 +0100:

<SNIP>

Well, it took a while but finally my dense brain actually was able to "see"
what was going on in all of this code and I've modified it and even added to
it and it is all working great now.

BTW, I emailed you from your web page and it bounced. I've tried again and
so far the second attempt has not come back on me.

Thanks again for your help. Now I need to see what else I would like to
'automate'. <g>

Colonel Blip.
E-mail: (e-mail address removed)
 

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