×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Resizing image in Word VB macro

Resizing image in Word VB macro

Resizing image in Word VB macro

(OP)
Hi,

My company recently changed its logo and I now need to change it on hundreds Word documents, in the header.

I wrote a macro to fulfill this task. It works well but just doesnt resize the image. Any help is welcome.

Thanks in advance.

Sub SwapLogo()
'
' SwapLogo Macro
' Macro enregistrée le 24/02/04 par guichard cyril
'
    '=============== Activation de l'entête dde document ==========
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    
    '=============== Dimensionnement des hauteurs de lignes du tableau ==========
    Selection.Cells.HeightRule = wdRowHeightAuto
    With Selection.Tables(1).Rows
        .Alignment = wdAlignRowLeft
        .AllowBreakAcrossPages = True
        .SetLeftIndent LeftIndent:=CentimetersToPoints(0.13), RulerStyle:= _
            wdAdjustNone
    End With
    Selection.SelectRow
    Selection.Cells.SetHeight RowHeight:=15, HeightRule:=wdRowHeightExactly
    With Selection.Rows
        .Alignment = wdAlignRowLeft
        .AllowBreakAcrossPages = True
        .SetLeftIndent LeftIndent:=CentimetersToPoints(0.13), RulerStyle:= _
            wdAdjustNone
    End With
    Selection.Move Unit:=wdRow, Count:=1
    Selection.SelectRow
    Selection.Cells.SetHeight RowHeight:=36, HeightRule:=wdRowHeightExactly
    With Selection.Rows
        .Alignment = wdAlignRowLeft
        .AllowBreakAcrossPages = True
        .SetLeftIndent LeftIndent:=CentimetersToPoints(0.13), RulerStyle:= _
            wdAdjustNone
    End With
    Selection.Move Unit:=wdRow, Count:=1
    Selection.SelectRow
    Selection.Cells.SetHeight RowHeight:=15, HeightRule:=wdRowHeightExactly
    With Selection.Rows
        .Alignment = wdAlignRowLeft
        .AllowBreakAcrossPages = True
        .SetLeftIndent LeftIndent:=CentimetersToPoints(0.13), RulerStyle:= _
            wdAdjustNone
    End With
    
    '=============== On efface l'ancien logo ==========
    Selection.Cells(1).Select
    Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1
    
    '=============== Fusion des cellules ==========
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
    Selection.Cells.Merge
    
    '=============== Insertion nouveau logo ==========
    Selection.InlineShapes.AddPicture FileName:="D:\logos\logo_black.jpg", _
        LinkToFile:=False, SaveWithDocument:=True
       
    '=============== Redimensionnement de la colonne =========
    Selection.SelectColumn
    With Selection.Cells
        .SetWidth ColumnWidth:=80, RulerStyle:=wdAdjustFirstColumn
        .VerticalAlignment = wdAlignVerticalCenter
    End With
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
        
    '=============== Redimensionnement du logo =========
    Selection.ShapeRange.Select
    With Selection.ShapeRange
        .ScaleHeight 300, msoFalse, msoScaleFromTopLeft
        .ScaleWidth 300, msoFalse, msoScaleFromTopLeft
    End With

    
    '=============== Retour au corps de document ==========
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    
End Sub


The returned error says the object doesnt exist in the library.

Cyril Guichard
Mechanical Engineer

RE: Resizing image in Word VB macro

It looks like you take the ShapeRange twice (so you are basically looking at: Selection.ShapeRange.ShapeRange.ScaleHeight)
Delete the line Selection.ShapeRange.Select, and keep the With ... End With part.
Hope this works, since I couldn't test it, of course.
Salut!

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

RE: Resizing image in Word VB macro

(OP)
nope it doesnt work either, already tried this one.

Wish their was a Selection.SelectShape available, as there is a Selection.SelectColumn. It would make things alot more easier...

Cyril Guichard
Mechanical Engineer

RE: Resizing image in Word VB macro

Selection.ShapeRange gives you all the shapes in the selection, but you can pick, for example, the first one by Selection.ShapeRange(1) which is equal to using Selection.ShapeRange.Item(1). This should give you a handle on only the first shape.
Can you step through the code and see how the selection changes as you select the table/column/shapes?

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

RE: Resizing image in Word VB macro

(OP)
well, from the error returned, it looks like my image isn't created, but it is. When I try to call it as item, Word says there is no item found in the column. Weird stuff.

Cyril Guichard
Mechanical Engineer

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close