Consulting

Results 1 to 4 of 4

Thread: How to use Excel VBA to run MS-word VBA command

  1. #1

    How to use Excel VBA to run MS-word VBA command

    I create a excel file as database / interface,
    and It would be established a MS Word file for reporting.
    The report was consists the picture files ( Insert a file ),

    I use the Excel command to compress the picture automatics and rename to save the MS word file as below
    but sometimes it is failed to compress or they have not asked the new file name, even no any alert to save the file,
    the coding as below,

    Coding :
    With objDoc.CommandBars.FindControl(ID:=6382)
    SendKeys "%a%e%w~{Enter}"
    .Execute
    End With

    Dim fName, fPath

    fName = InputBox("Enter the file Name : Report - ", "Save As New File Name", Format(Now(), "DD-MMM-YYYY"))
    fPath = Sheets("Master").Range("B1").Value


    Application.DisplayAlerts = True
    objDoc.SaveAs fPath & "Report - " & fName & ".doc"

    End Coding


    I checked the VBA code if run in MS word as below, but how can I run the code in Excel VBA coding

    Coding :

    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    ActiveDocument.Save

    End Coding

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,088
    Location
    There is no reliable VBA method available for image compression in Word 2007 & later. Although Word 2007 & later contain the same command bar as Word 2003 & earlier (ID:=6382), it doesn’t work. Indeed Word 2007 & later contain two command bars with the same ID but it’s only the older non-functioning one your code activates. SendKeys is also unreliable, since its results are entirely dependent on which process & window is active when it runs.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    Can I save as old version word file, might it fulfill the requirement?

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,088
    Location
    Changing the file format won't help; it's the Word version that matters.
    Cheers
    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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