Solved

How to set the Horizontal alignment Property of a Picture Object in a Word Document?

Posted on 2002-04-15
11
627 Views
Last Modified: 2007-11-27
Hi,

How to set the Horizontal alignment Property of a Picture Object in a Word Document?

In a table, i add a picture. I need to set the Picture's Property (Right Click picture > Select Format Picture > go to Layout Tab > Horizontal aligment)?

I think i got the code i want but still cannot make it. Can someone guide or customize my codes a bit?

Here is the codes:

Dim myWord As New Word.Application
Dim myfileName As String

Private Sub cmdOpenWord_Click()
   
    myWord.Visible = True
    myWord.Documents.Add
   
    myWord.ActiveDocument.Tables.Add myWord.ActiveDocument.Range, txtRow, txtCol ' wdAlignTabRight ', wdAutoFitContent
    myWord.Activate
   
    'Set Border to None
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderBottom) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderDiagonalDown) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderDiagonalUp) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderHorizontal) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderLeft) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderRight) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderTop) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderVertical) = wdNone
   
    'myWord.ActiveDocument.Shapes.AddPicture myfileName
    myWord.ActiveDocument.Tables(1).Cell(1, 1).Select
   
    For i = 1 To 25
        j = j & "Hello World " & Chr$(12)
    Next i
   
    myWord.ActiveDocument.Tables(1).Cell(1, 1).Range.InsertAfter j
   
    myWord.ActiveDocument.Shapes.AddPicture myfileName
    myWord.ActiveDocument.Shapes(1).WrapFormat.Side = wdWrapRight
    myWord.ActiveDocument.Shapes(1).WrapFormat.Type = wdWrapTight
   
'    myWord.ActiveDocument.Shapes(1).AutoShapeType = wdHorizontalLineAlignRight
'    myWord.ActiveDocument.Shapes(1).AutoShapeType = wdHorizontalLineAlignRight
    'myWord.ActiveDocument.Tables(1).Columns(1).Width = 120
End Sub

* I need to solve this problem before Tuesday. Points will be added to fast and accurate answer. Thanks.
0
Comment
Question by:Ryan Chong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 52

Author Comment

by:Ryan Chong
ID: 6943591
Anybody.. ?
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6947127
ping

Busy now, check with you later.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6947501
Hi,
I don't see Layout Tab (in Word 97), but you can do this:

1. go to menu Tools, Macro, select "Record new Macro"
2. Macro recorder is running and whatever you do will be recorded.  Now, select Layout Tab and do the alignment of the picture.
3. Stop Recording
4. Now, in the list of macros, select your macro and press Edit - this will show the generated code, which can be used inside your VB application with some minor modifications.

Also, use "Option Explicit", don't use "As New" in declarations, and don't use default properties like "txtRow" - use "txtRow.Text".
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 7

Expert Comment

by:weesiong
ID: 6947964
ryancys,

Try change this:
myWord.ActiveDocument.Shapes(1).AutoShapeType = wdHorizontalLineAlignRight

To:
myWord.ActiveDocument.Shapes(1).HorizontalLineFormat.Alignment = wdHorizontalLineAlignRight

From: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10/html/woproAlignment.asp
0
 
LVL 52

Author Comment

by:Ryan Chong
ID: 6964703
Hi pals,

Sorry for the long delay, not working for a week already so don't get a chance to reply this question.

Now i was able to Align the picture like this:

Private Sub opt_Click(Index As Integer)
    Select Case Index
    Case 0
        myWord.ActiveDocument.Shapes(1).Left = 0
    Case 1
        myWord.ActiveDocument.Shapes(1).Left = (myWord.ActiveDocument.Tables(1).Cell(1, 1).Width - myWord.ActiveDocument.Shapes(1).Width) / 2
    Case 2
        myWord.ActiveDocument.Shapes(1).Left = myWord.ActiveDocument.Tables(1).Cell(1, 1).Width - myWord.ActiveDocument.Shapes(1).Width
    End Select
End Sub

But here is a problem, how can i add a picture on certain rows in a Table? I have tried but still can't get it yet!

* use this line to add rows on a table:
myWord.ActiveDocument.Tables(1).Rows.Add

Any suggestion or useful links on Word VBA? Thanks
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6964735
so nice wow, can relax 1 week
0
 
LVL 52

Author Comment

by:Ryan Chong
ID: 6964923
0
 
LVL 52

Author Comment

by:Ryan Chong
ID: 6967604
For ameba, thanks for provide me an alternative, but unfortunately i can't record for the picture editing part (Cannot change Picture Format when macro is recording), so i failed to solve the problem, until TimCottee solve the problem for me at this PAQ question:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20292962

So, can i PAQ this question for 0 points?

0
 
LVL 15

Expert Comment

by:ameba
ID: 6967872
That's good idea.  PAQ it!
0
 
LVL 52

Author Comment

by:Ryan Chong
ID: 6970512
Thanks :)
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 6970953
Points reduced and question put in PAQ


Thanks
COmputer101
E-E Moderator
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question