Avatar of Clif
Clif
Flag for United States of America asked on

Automating Word - Error on Users Machine, Can't Duplicate On Mine

I am developing an application that creates (from scratch) a Word document.  I'm developing using VB.Net 2010 (Pro).  I have on my machine MS Office 2010, the user has Office 2003, so I'm using late binding.

Here is the block of code that's failing
    Dim shp As Object = oTable.Cell(1, 1).Range.InlineShapes.AddPicture(sBMPFile)
    With shp
        writeLog("Adjust Image Size", "clsReport", "writePage05")
        .LockAspectRatio = 1
        Dim fOldWidth As Single = .Width
        writeLog("Adjust Image Width", "clsReport", "writePage05")
        .Width = m_oWord.InchesToPoints(4)
        If .Height > m_oWord.InchesToPoints(4.5) Then
            writeLog("Adjust Image Height", "clsReport", "writePage05")
            .Height = m_oWord.InchesToPoints(4.5)
        End If
    End With

Open in new window


Specifically, I have localized the error to occur at the "LockAspectRatio" line, or the line after.

The error that's thrown is this:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentException: The specified value is out of range.
   at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType)
   at STR_Tower_Mapping_Report_Maker.clsReport.writePage_05()

Yada, yada, yada

Open in new window


I'm fairly certain the issue is the fact that the "LockAspectRatio" value should be "msoTrue", but since I'm late binding I'm merely guessing at the actual numeric value.

Any ideas?
Visual Basic.NETMicrosoft WordMicrosoft Office

Avatar of undefined
Last Comment
Clif

8/22/2022 - Mon
Patrick Tallarico

My suspicion is that it may be calling this from a vba library that your users may not have loaded.  Open the VBA console, and go to 'Tools' -> 'References' and check to make sure that the libraries you have on your machine are checked for your users.
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jacques Bourgeois (James Burger)

If the error is on line 5, remove it, you do not use that variable anywhere in your code.

You might want to provide the use with Word 2003 with a Debug version of the application. You would get more information out of the error report.

However, as it is, it gives a clue. Look at the last line, this is typically the line that triggered the error:

at STR_Tower_Mapping_Report_Maker.clsReport.writePage_05()

What is that STR_Tower_Mapping_Report_Maker?
GrahamSkan

The constant msoCTrue has a value of 1. msoTrue is -1, so that is the value to use

msoCTrue produces the error on my 2003 version.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Clif

ASKER
Sorry it took so long to get back, but the user was out of the office for a few days, so they couldn't test it.

The change from 1 to -1 did the trick.

Thanks.