Solved

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

Posted on 2002-04-15
11
622 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 49

Author Comment

by:Ryan Chong
Comment Utility
Anybody.. ?
0
 
LVL 7

Expert Comment

by:weesiong
Comment Utility
ping

Busy now, check with you later.
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
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
 
LVL 7

Expert Comment

by:weesiong
Comment Utility
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 49

Author Comment

by:Ryan Chong
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Expert Comment

by:weesiong
Comment Utility
so nice wow, can relax 1 week
0
 
LVL 49

Author Comment

by:Ryan Chong
Comment Utility
0
 
LVL 49

Author Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
That's good idea.  PAQ it!
0
 
LVL 49

Author Comment

by:Ryan Chong
Comment Utility
Thanks :)
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
Points reduced and question put in PAQ


Thanks
COmputer101
E-E Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now