Solved

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

Posted on 2002-04-15
11
625 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
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 51

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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 51

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 51

Author Comment

by:Ryan Chong
ID: 6964923
0
 
LVL 51

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 51

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 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