Log in

View Full Version : [SOLVED:] How to use Excel VBA to run MS-word VBA command



justuptou
09-26-2017, 10:05 PM
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

macropod
09-26-2017, 11:36 PM
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.

justuptou
09-27-2017, 12:17 AM
Can I save as old version word file, might it fulfill the requirement?

macropod
09-27-2017, 12:22 AM
Changing the file format won't help; it's the Word version that matters.