VBA for Resizing graphics

C

Colonel Blip

Hello, All!

First, I am NOT a VBA programmer, although with use of the macro recorder
and help from MVP's on Outlook and Word I've managed to created a bunch of
macros for those applications.

With Publisher I am stuck, since there is no recorder to help. I have a
simple macro I would like to create. I typically print 4x6 photos using
Publisher 2003. When I open my photo it comes into publisher BIG, so I
always have to do a Format and Size to get it down to the size I want. I
would like to create a macro to do this.

Anyone here knowledgeable in vba code that could help? Thanks.


With best regards, Colonel Blip. E-mail: (e-mail address removed)
 
J

John Inzer

Colonel said:
Hello, All!

First, I am NOT a VBA programmer, although with use of
the macro recorder and help from MVP's on Outlook and
Word I've managed to created a bunch of macros for those
applications.

With Publisher I am stuck, since there is no recorder to
help. I have a simple macro I would like to create. I
typically print 4x6 photos using Publisher 2003. When I
open my photo it comes into publisher BIG, so I always
have to do a Format and Size to get it down to the size I
want. I would like to create a macro to do this.

Anyone here knowledgeable in vba code that could help?
Thanks.


With best regards, Colonel Blip. E-mail:
(e-mail address removed)
===================================
If you are running Pub2003, I must assume
that you may be running Windows XP...

For simple printing of 4x6 images...auto
rotated three per page...you can use the
Windows Printing Wizard. Just open a
folder that contains image files...select
one or more files...right click the selected
files and from the menu...choose print.

If your images require cropping...you might
like the freebie at the following link...yes,
it works on Windows XP.

Download free ArcSoft
PhotoPrinter 2.0 LE
http://tinyurl.com/ixmn
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
Colonel Blip said:
I then opened the document and get a debug error in the line
"Private Sub Document_Open()"

Does it say what the error is?

Do you have the SP1 patch for Office 2003?
 
C

Colonel Blip

Hello, Ed!
You wrote on Tue, 12 Oct 2004 20:19:26 +0100:

EB> A small child turns to Ed, and exclaims: "Look! Look! A post from
EB> Colonel Blip <[email protected]>!"...
??>> I then opened the document and get a debug error in the line
??>> "Private Sub Document_Open()"

EB> Does it say what the error is?

Compile Error:
Syntax error

EB> Do you have the SP1 patch for Office 2003?

Yes.

With best regards, Colonel Blip. E-mail: (e-mail address removed)
 
C

Colonel Blip

Hello, Ed!
You wrote on Tue, 12 Oct 2004 20:19:26 +0100:

EB> A small child turns to Ed, and exclaims: "Look! Look! A post from
EB> Colonel Blip <[email protected]>!"...
??>> I then opened the document and get a debug error in the line
??>> "Private Sub Document_Open()"

EB> Does it say what the error is?


A different take on the message:

If I place the cursor at the "Private Sub Document_Open()" and hit F8 then
the error is:

Compile Error:
Method or data member not found

As I recall the group doesn't like files uploaded, correct? Otherwise I
could send the file with the macro in it.

With best regards, 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:
Another question, is there a way to have this macro work on all of my
templates or do I have to add it to each one?

You would have to add the macro to each one, or create an add-in.
 
C

Colonel Blip

Hello, Ed!
You wrote on Wed, 13 Oct 2004 18:25:30 +0100:

Thanks, I suspect add-ins are WAY beyond me. I'll adjust the templates.

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:
Thanks, I suspect add-ins are WAY beyond me. I'll adjust the
templates.

Add-ins aren't that much more complicated to write than macros - but you do
need to have Visual Basic or another COM-compatible programming language
installed to create them.
 
C

Colonel Blip

Hope I don't wear out my welcome on this, but I have a couple of questions. <g>

I would like to put this macro (and others similar to it, with only the size changed) on my custom toolbar. I have found a list of FaceID's that I can use to change the macros I will install (the one you helped with IMMENSELY, and two others - one for 8x10 and the other 4x5.5)

I've listed the macro below for an 8x10, only changing the caption, faceID and the action to be taken. My questions:

Have I interpreted the macro correctly and made the right changes?
Is there a way to make this show up on my custom toolbar?

On a related issue, I can live with the macro enable dialog when I open my templates, but for Excel and Word I have the security set to High and used selfcert to sign my macros in those apps. Not sure how to do this in Publisher.

Thanks again.

--
Colonel Blip
(e-mail address removed)
Remove "removethespam" when replying.
__________________________________

Dim WithEvents cbbMyButton As Office.CommandBarButton


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 = 720
.Height = 576
Else
.Width = 576
.Height = 720
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 8"" by 10""").Delete
End Sub

Private Sub Document_Open()
On Error Resume Next
Set cbbMyButton = CommandBars(3).Controls.Add(, , , , True)
cbbMyButton.FaceId = 203
cbbMyButton.Caption = "Resize selection to 8"" by 10"""
End Sub
 
C

Colonel Blip

Whoops,

Discovered one problem with this approach already. There apparently can only be one macro. I tried creating the 8x10 along with the 4x6 and the added one gives me an error setting up the button on the command line at: "Private Sub cbbMyButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)"


--
Colonel Blip
(e-mail address removed)
Remove "removethespam" when replying.
__________________________________


Hope I don't wear out my welcome on this, but I have a couple of questions. <g>

I would like to put this macro (and others similar to it, with only the size changed) on my custom toolbar. I have found a list of FaceID's that I can use to change the macros I will install (the one you helped with IMMENSELY, and two others - one for 8x10 and the other 4x5.5)

I've listed the macro below for an 8x10, only changing the caption, faceID and the action to be taken. My questions:

Have I interpreted the macro correctly and made the right changes?
Is there a way to make this show up on my custom toolbar?

On a related issue, I can live with the macro enable dialog when I open my templates, but for Excel and Word I have the security set to High and used selfcert to sign my macros in those apps. Not sure how to do this in Publisher.

Thanks again.

--
Colonel Blip
(e-mail address removed)
Remove "removethespam" when replying.
__________________________________

Dim WithEvents cbbMyButton As Office.CommandBarButton


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 = 720
.Height = 576
Else
.Width = 576
.Height = 720
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 8"" by 10""").Delete
End Sub

Private Sub Document_Open()
On Error Resume Next
Set cbbMyButton = CommandBars(3).Controls.Add(, , , , True)
cbbMyButton.FaceId = 203
cbbMyButton.Caption = "Resize selection to 8"" by 10"""
End Sub
 
E

Ed Bennett

A small child turns to Ed, and exclaims: "Look! Look! A post from
Colonel Blip said:
Whoops,

Discovered one problem with this approach already. There apparently
can only be one macro. I tried creating the 8x10 along with the 4x6
and the added one gives me an error setting up the button on the
command line at: "Private Sub cbbMyButton_Click(ByVal Ctrl As
Office.CommandBarButton, CancelDefault As Boolean)"

I'm not sure if/how you can certify your own Publisher macros (I'll look
into it, though)

You aren't going to wear out your welcome any time soon, but the
microsoft.public.publisher.programming group might be the place to take this
for further discussion

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

If you replace CommandBars(3) with CommandBars("CaptionOfMyCustomToolbar"),
you will get the buttons added to your custom toolbar.

Alternatively, you can declare a new variable

Dim cbMyCommandBar As CommandBar

and then:

Set cbMyCommandBar = CommandBars("CaptionOfMyCustomToolbar")

Then you will be able to use cbMyCommandBar (or a shorter variable name)
instead of CommandBars("CaptionOfMyCustomToolbar")

In addition, I think you can only have one Document_Open() event, so you may
want to move code out of that and into a ResizeObjectTo4x6() method or
something.

Alternatively, you could define a generic ResizeObject(WidthInInches As
Single, HeightInInches As Single), and edit the code so that it takes the
values from WidthInInches and HeightInInches (multiplied by 72, of course) -
so you would have one general method, making it easier to add more buttons
in future. You'd just call this method, instead of copying another sub and
changing values.

HTH!
 
C

Colonel Blip

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

Ok, I will work on these with your suggestions. Also, I will hook into the
programming forum as well.

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

Colonel Blip

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.
 

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