Results 1 to 5 of 5

Thread: Macros (vba)

  1. #1
    2 Star Lounger
    Join Date
    Jul 2001
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macros (vba)

    Attached to this post should be a word document that has a layout that looks like it fits a cd. What I want to be able to do is record a macro that puts text in the thin branches vertically, a text description in the main box, and a picture in the lower box formatted to fit inside the box. I need code that will do this!!!! I usually just record a macro and modify that but for the love of god when I turn macro record on it starts doing funny things. In the end, the macro will get variables from another source in order to fill in the fields but for now could somebody please give me the code to do what I had asked?? I have never programmed in Word before, only in excel!!

    Thanks
    Attached Files Attached Files

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (vba)

    If you have programmed with VBA in Excel, then it should not be too hard to do Word VBA.

    I would suggest starting with Steve Roman's book, Writing Word Macros.
    See the Word VBA book list at my URL below.

    Also, since you are familiar with Excel VBA, if you do not already have it, get John Walkenbach's Excel 2002 Power Programming with VBA (ISBN: 0764547992). A number of topics in John's book can easily be applied to Word VBA.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (vba)

    kiyanis,

    Insert bookmarks where you want text (Insert, Bookmark)- call it, say "myBookmark". Make sure you can see the bookmarks- it helps in the layout (Tools, Options, check "Bookmarks" under the default View tab). Write some code like:<pre>Dim rngTarget As Range
    Set rngTarget = ActiveDocument.Bookmarks("myBookmark").Range
    rngTarget.Text = "abc"
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    2 Star Lounger
    Join Date
    Jul 2001
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (vba)

    Yeah, that works really well thanks, how about inserting a picture and resizing it ??

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macros (vba)

    Mmmm... how about it? Here's what I propose:

    Create a new document and turn on macro record. Then choose Insert|Picture|From File... and insert a picture. Turn off the macro recorder. Open the editor. You should have something like this:

    Sub Macro3()
    '
    ' Macro3 Macro
    ' Macro recorded 11/17/2002 by Joe Blow
    '
    Selection.InlineShapes.AddPicture FileName:= _
    "C:AcrobatError.bmp", LinkToFile:=False, SaveWithDocument:=True
    End Sub

    Recording macros in baby steps can help you isolate the critical objects and methods. Now you said that you want to manipulate the InlineShape after adding it, so you can change your method call to the form that returns an object. If you're not conversant with the standard way to do this, you can use the online help by selecting AddPicture in the recorded macro and hitting F1.

    Dim myPic as InlineShape
    Set myPic = Selection.InlineShapes.AddPicture(FileName:= _
    "C:AcrobatError.bmp", LinkToFile:=False, SaveWithDocument:=True)

    Now you need to know how to change the image size. Select InlineShape and hit F1 to see the properties (e.g., Height) and how the units of measure work.

    I think you can handle it from here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •