Link to home
Start Free TrialLog in
Avatar of mjburgard
mjburgardFlag for United States of America

asked on

VBA script error

When I run the following, I get an error only when twosided = false.  It runs normally when twosided = true.
If xlSheet.Range("PFNumSides") = "2" Then
            twosided = True
        Else
            twosided = False
        End If
        
    'Page cover - ink
    For i = 1 To wdDoc.ContentControls.Count
        If wdDoc.ContentControls(i).Title = "inks1" Then
            If xlSheet.Range("PrintFoldColor").Text = "Color/Black&White" Then
                wdDoc.ContentControls(i).Range.Text = "4/1"
            Else
                If xlSheet.Range("printFoldColor").Text = "Color" Then
                    If twosided = True Then
                        wdDoc.ContentControls(i).Range.Text = "4/4"
                    Else
                        wdDoc.ContentControls(i).Range.Text = "4/0"
                    End If
                    Exit For
                Else
                    If twosided = True Then
                        wdDoc.ContentControls(i).Range.Text = "1/1"
                    Else
                        wdDoc.ContentControls(i).Range.Text = "1/0"
                    End If
                    Exit For
                End If
                Exit For
            End If
            Exit For
        End If
    Next

Open in new window

The error says "Automation error Call was rejected by callee."
Any ideas?
Avatar of RobSampson
RobSampson
Flag of Australia image

What type of object is that content control?  Maybe it's trying to interpret it literally as a division by zero.

Try
wdDoc.ContentControls(i).Range.Text = CStr("4/0")

Rob.
Avatar of mjburgard

ASKER

Thanks rob, but that is going into a microsoft word document as text. - and last night it mysteriously started working - I have no explanations at this point.

I am going to mark this as completed - but ...
ASKER CERTIFIED SOLUTION
Avatar of mjburgard
mjburgard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you read my previous comment, you will see that it just started working last night.

I still have no idea why, but I no longer have a problem if it is working.