Re: Word Programming - issue with Word versions and automation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Edward Thrashcort was telling us:
Edward Thrashcort nous racontait que :

> Keep up Bond!

Was that really necessary?

> We are talking about statements is higher versions of Word causing
> compiler errors in earlier versions EVEN when inside regular If blocks

I know, have you read the whole thread or just the part where you jumped in?
Just in case, here is what I wrote earlier, complete with all the
syntactical, spelling and grammatical errors:

<quote>
Sorry about your situation, but, I created the code I posted in a Word 2003
document, saved it and ran the code.
Then, I opened the document with Word 97 and Word 2000 and ran the code
without any problems...

I have done this kind of thing before and never had any problems, so I do
not understand why you are having problems with this.

Conditioning compiling (#If) is normally used for making a difference
between a Mac or a PC machine, but regular conditional branching has always
worked for my purposes. I guess this is why there are no Compiler constants
for Word versions, they are not necessary.

Of course I cannot compile this code under Word 2000 or 97, but why would I
want to? I coded,debugged and compiled the whole thing in Word 2003.
When you run the code, the compiler only compiles the Subs/Functions you
call, this is why I suggested calling the appropriate Sub according to the
version you are running, as in my example.

I mean, the following code will not work:

'_______________________________________
Sub test()

Dim myVer As Long
myVer = Val(Left$(Application.Version, 1))

With ActiveDocument
MyName = Left(.FullName, Len(.FullName) - 4) & "_New.doc"
End With

Select Case myVer
Case 1
ActiveDocument.SaveAs FileName:=MyName, InsertLineBreaks:=True
Case 8, 9 '97 or 2000
ActiveDocument.SaveAs FileName:=MyName
Case Else
MsgBox "I don't know what you are running."
End Select

End Sub
'_______________________________________

But the code I have already posted will.
Why did you not try it?
Or if you did, what kind of error message did you get?
</quote>

And the code I refer to from an earlier mesaage is:
<quote>
'_______________________________________
Public MyName As String

'_______________________________________
Sub test()

Dim myVer As Long
myVer = Val(Left$(Application.Version, 1))

With ActiveDocument
MyName = Left(.FullName, Len(.FullName) - 4) & "_New.doc"
End With

Select Case myVer
Case 1
WordXpAndMore
Case 8, 9 '97 or 2000
Word2000AndMinus
Case Else
MsgBox "I don't know what you are running."
End Select

End Sub
'_______________________________________

'_______________________________________
Sub Word2000AndMinus()

ActiveDocument.SaveAs FileName:=MyName

End Sub
'_______________________________________

'_______________________________________
Sub WordXpAndMore()

ActiveDocument.SaveAs FileName:=MyName, InsertLineBreaks:=True

End Sub
'_______________________________________
</quote>

Would you care to test it on various versions of Word? It did work for me on
Word 2003, Word 2000 and Word 97.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@xxxxxxxxxxxxxxxxxxxxxxx
Word MVP site: http://www.word.mvps.org


.



Relevant Pages

  • Re: Word Programming - issue with Word versions and automation
    ... I guess this is why there are no Compiler ... this is why I suggested calling the appropriate Sub according to the ... > Sub test() ... > Dim myVer As Long ...
    (microsoft.public.word.vba.general)
  • Re: performance of subs vs. functions
    ... The compiler does not produce any functional code for the two examples. ... In fact I had to force the function or sub to do something before the compiler produced any real ... Public Function StubFunc() As Boolean ... Public Sub StubSub() ...
    (microsoft.public.vb.general.discussion)
  • Re: Integer Dos And Donts
    ... Public Class MainForm ... //000009: Public Shared Sub Main ... Imports Int = System.Int64 ... Only one compiler is needed. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Overloaded constructors
    ... constructors with a private initialization function is indeed the perfect ... class as the first line of the Sub New. ... Public Sub New ... the compiler knows that it doesn't need to call the base ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Assumed shape array help
    ... >> call sub ) ... >> subroutine sub ... >> by use of a nasty explicit interface/module, the compiler still checks ... > dimensional arrays. ...
    (comp.lang.fortran)