×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

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!


Resources