MS Office Forum / Word / Programming / September 2005
Word Programming - issue with Word versions and automation
|
|
Thread rating:  |
Aminc - 15 Sep 2005 21:28 GMT I have a program (DOT) running behind Msword via an application. One of the automation is to save the active document using MS DOS With Layout format to retain formatting etcetera. This works fine in Word 97/2000/XP. However, in Word 2003, use of this converter requires InsertLineBreaks:=True so that line breaks are inserted (without this a paragraph ends up as a single line in ASC file).
Does anybody know a workaround method where the same program can work for all versions without major changes?
 Signature AminC
Michael Bednarek - 16 Sep 2005 10:42 GMT On Thu, 15 Sep 2005 13:28:04 -0700, "Aminc" <Aminc@discussions.microsoft.com> wrote in microsoft.public.word.vba.general:
>I have a program (DOT) running behind Msword via an application. One of the >automation is to save the active document using MS DOS With Layout format to [quoted text clipped - 5 lines] >Does anybody know a workaround method where the same program can work for >all versions without major changes? Use Application.Build and If or Select Case to code for the different versions.
 Signature Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Aminc - 16 Sep 2005 14:38 GMT Sure. I can do that... but problem is when I use InsertLineBreaks:=True (for Word 2003), I cannot compile it in Word 2000 or Word 97 because that property is unavailable.
 Signature AminC
> On Thu, 15 Sep 2005 13:28:04 -0700, "Aminc" > <Aminc@discussions.microsoft.com> wrote in [quoted text clipped - 12 lines] > Use Application.Build and If or Select Case to code for the different > versions. Jean-Guy Marcil - 16 Sep 2005 15:44 GMT Aminc was telling us: Aminc nous racontait que :
> Sure. I can do that... but problem is when I use > InsertLineBreaks:=True (for Word 2003), I cannot compile it in Word > 2000 or Word 97 because that property is unavailable. I think you isunderstood Michael suggestion. He was suggesting womthing like:
Dim myVer As Long myVer = Val(Left$(Application.Version, 1))
Select Case myVer Case 1 MsgBox "You are running Xp or higher." Case 9 '2000 MsgBox "You are running 2000." Case 8 '1997 MsgBox "You are running 97." Case Else MsgBox "I don't know what you are running." End Select
Replace the MsgBox with calls to an appropriate Sub.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Aminc - 16 Sep 2005 15:58 GMT Agreed Jean-Guy, but I guess I am not able to explain. Problem is that InsertLineBreaks argument with the ActiveDocument.SaveAs is unavailable in versions prior to 2003. So if I code to pass InsertLineBreaks:=True is user is running say 2000 or 97, I am unable to compile the program.
 Signature AminC
> Aminc was telling us: > Aminc nous racontait que : [quoted text clipped - 21 lines] > > Replace the MsgBox with calls to an appropriate Sub. Jean-Guy Marcil - 16 Sep 2005 16:21 GMT Aminc was telling us: Aminc nous racontait que :
> Agreed Jean-Guy, but I guess I am not able to explain. Problem is that > InsertLineBreaks argument with the ActiveDocument.SaveAs is > unavailable in versions prior to 2003. So if I code to pass > InsertLineBreaks:=True is user is running say 2000 or 97, I am unable > to compile the program. Are you saying that something like this will not work on your machine:
'_______________________________________ 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 '_______________________________________
Or are you, like me, one of those people who understands things really quickly if they are explained long enough? ;-)
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Aminc - 16 Sep 2005 16:35 GMT Look. I know how to switch between passing selective arguments based on Word version. Here is the problem. If I code it like you suggested (I already had done that before starting this whole communication), and compile in Word2000 or 97, there is a compile error because the InsertLineBreaks argument isn't available in 2000 or 97. I surely can compile in Word 2003 using this argument but then cannot run the program in 2000/97 because again InsertLineBreaks is not available and there is a run time error.
 Signature AminC
> Aminc was telling us: > Aminc nous racontait que : [quoted text clipped - 50 lines] > Or are you, like me, one of those people who understands things really > quickly if they are explained long enough? ;-) Jean-Guy Marcil - 16 Sep 2005 18:36 GMT Aminc was telling us: Aminc nous racontait que :
> Look. I know how to switch between passing selective arguments based > on Word version. Here is the problem. If I code it like you suggested [quoted text clipped - 4 lines] > program in 2000/97 because again InsertLineBreaks is not available > and there is a run time error. 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?
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Edward Thrashcort - 16 Sep 2005 16:44 GMT Only conditional compilation will do it BUT (unbelievably) there is no built-in compiler constant for Word version.
Sub ConditionalCompile() 'You cannot declare #Constants dynamically #Const MyWordVersion = 10
#If MyWordVersion > 9 Then MsgBox "You are running Xp or higher." #ElseIf MyWordVersion = 9 Then MsgBox "You are running 2000." #ElseIf MyWordVersion = 8 Then MsgBox "You are running 97." #Else MsgBox "I don't know what you are running." #End If
End Sub
Eddie
> Aminc was telling us: > Aminc nous racontait que : [quoted text clipped - 50 lines] > Or are you, like me, one of those people who understands things really > quickly if they are explained long enough? ;-) Jean-Guy Marcil - 16 Sep 2005 18:38 GMT Edward Thrashcort was telling us: Edward Thrashcort nous racontait que :
> Only conditional compilation will do it BUT (unbelievably) there is no > built-in compiler constant for Word version. It would be nice, but I guess there are none becasue they are not necessary since regular If blocks with calls to different Subs will work.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Edward Thrashcort - 16 Sep 2005 21:13 GMT Keep up Bond!
We are talking about statements is higher versions of Word causing compiler errors in earlier versions EVEN when inside regular If blocks
Eddie
> Edward Thrashcort was telling us: > Edward Thrashcort nous racontait que : [quoted text clipped - 4 lines] > It would be nice, but I guess there are none becasue they are not > necessary since regular If blocks with calls to different Subs will work. Jean-Guy Marcil - 17 Sep 2005 00:01 GMT 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.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Edward Thrashcort - 18 Sep 2005 01:40 GMT > I know, have you read the whole thread or just the part where you jumped Evidently I may have missed some messages. Apologies. I had not associated that message with you.
> > Keep up Bond! > > Was that really necessary? Maybe you don't understand English humour? It was meant as a friendly rebuke - albeit that it turned out I was wrong!
No offense intended.
I'm glad the the problem is solved by compiling only in 2003. However I am surprised that Jon West's suggestion works - it will still work in earlier version. I assume it's being distributed as an executable addin?
Eddie
> Edward Thrashcort was telling us: > Edward Thrashcort nous racontait que : [quoted text clipped - 109 lines] > Would you care to test it on various versions of Word? It did work for me > on Word 2003, Word 2000 and Word 97. Jean-Guy Marcil - 18 Sep 2005 19:28 GMT Edward Thrashcort was telling us: Edward Thrashcort nous racontait que :
>> I know, have you read the whole thread or just the part where you >> jumped > > Evidently I may have missed some messages. > Apologies. I had not associated that message with you. No problems.
>>> Keep up Bond! >> [quoted text clipped - 4 lines] > > No offense intended. None really taken because I wasn't sure on the intention. I slipped thatquestion in just to make sure. I have had lots of contacts with British people and their humour and love most British comedies (one of my favourite nowadays is Father Ted...) But it has been a while seen I have hung out with the Queen's subjects... Maybe a smiley would have helped?
> I'm glad the the problem is solved by compiling only in 2003. However > I am surprised that Jon West's suggestion works - it will still work > in earlier version. I assume it's being distributed as an executable > addin? I think he was suggesting exactly the same as me, except that at he recommended putting each Word version code in its own separate module (whereas I mentioned using separate Subs/Functions). You can write code for Word 2003 and run it under Word 2000 as long as the Word 2003 code does not have to be compiled; which it will if you call the Sub containing the said code. I believe Jonathan suggested a different module to be sure it will not be compiled unless you explicitly call the module during execution.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Edward Thrashcort - 18 Sep 2005 21:39 GMT Glad we see eye to eye
> most British comedies (one of my favourite nowadays is Father Ted...) If you get the chance to see "My Hero" also starring "father Ted" (Ardal O'Hanlon) then give it a go. You will either love it or hate it but I think it's really funny!
> >>> Keep up Bond! I guess you realise that's a quote from an 007 where James Bond is being briefed about his latest gadgets?
Eddie
> Edward Thrashcort was telling us: > Edward Thrashcort nous racontait que : [quoted text clipped - 36 lines] > to be sure it will not be compiled unless you explicitly call the module > during execution. Jean-Guy Marcil - 19 Sep 2005 16:38 GMT Edward Thrashcort was telling us: Edward Thrashcort nous racontait que :
> Glad we see eye to eye > [quoted text clipped - 3 lines] > (Ardal O'Hanlon) then give it a go. You will either love it or hate > it but I think it's really funny! Yeah, saw that on late night BBC-Canada... It does have its funny moments... (BTW O'Hanlon does not play Father Ted, he plays the "simple" priest whose character name I can't remember right now...)
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Aminc - 16 Sep 2005 20:18 GMT OK. Here is the code. When I run it in Word 2000, I get Compile error - Named argument on found (on InsertLineBreaks:=)
Sub Test()
Dim MyFile As String Dim iAppversion As Integer
iAppversion = Left$(Application.Version, 2) Select Case iAppversion Case 11 Save2K3Document MyFile, wdFormatText ' Save the document in text format Case Else SaveDocument MyFile, FileConverters(iFormat).SaveFormat End Select
End Sub
Sub Save2K3Document(sDocName As String, Optional iFormat As Integer) ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat, InsertLineBreaks:=True End Sub
Sub SaveDocument(sDocName As String, Optional iFormat As Integer) ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat End Sub
 Signature AminC
> Only conditional compilation will do it BUT (unbelievably) there is no > built-in compiler constant for Word version. [quoted text clipped - 71 lines] > > Or are you, like me, one of those people who understands things really > > quickly if they are explained long enough? ;-) Jean-Guy Marcil - 16 Sep 2005 23:57 GMT Aminc was telling us: Aminc nous racontait que :
> OK. Here is the code. When I run it in Word 2000, I get Compile error > - Named argument on found (on InsertLineBreaks:=) [quoted text clipped - 24 lines] > ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat > End Sub I see some minor problems with your code: > iAppversion = Left$(Application.Version, 2) will not work with Word 2000 or less because Application.Version will return "9.0" or "8.0", so you will be trying to assign "9." or "8." to Integer as per your variable declaration. Also, remember that Application.Version returns a String, so in effect you are assigning a String to an Integer and letting the compiler silently doing the conversion, which is not a good idea, generally speaking..
Also, from your code I cannot tell how/where iFormat is defined, but that does not matter for the matter at hand.
I tested the following code on a Word 2000 machine and it ran as expected, i.e it worked, and I tested three times, closing Word in between.
Again, you cannot compile that code on a Word 2000 machine, but you can execute it without manually compiling because I believe that the compiler only compiles the Subs/Functions that are executed/called. In this case, on a Word 200 machine, "Save2K3Document" will not be called, so it is not compiled. At least this is how I understand it, and the only way I can think of to account for the fact the code actually runs on Word 2000 or Word 97.
So, either my machine is weird and runs code it should not, or yours is weird by not running code it should. It would be nice if someone else could test the code I posted earlier in this thread. I have tried it as is on three Word versions and it worked (Word 97, Word 200 and Word 2003).
Sub Test()
Dim MyFile As String Dim iAppversion As Integer
MyFile = ActiveDocument.FullName
iAppversion = Left$(Application.Version, 1)
Select Case iAppversion Case 11 Save2K3Document MyFile, wdFormatText ' Save the document in Text Format Case Else SaveDocument MyFile, FileConverters(1).SaveFormat End Select
End Sub
Sub Save2K3Document(sDocName As String, Optional iFormat As Integer)
ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat, InsertLineBreaks:=True
End Sub
Sub SaveDocument(sDocName As String, Optional iFormat As Integer)
ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat
End Sub
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Edward Thrashcort - 16 Sep 2005 16:53 GMT Burying an invalid statement inside an if statement does NOT get it past the compiler!
Sub ConditionalCompile() 'You cannot declare #Constants dynamically #Const MyWordVersion = 10
#If MyWordVersion > 9 Then MsgBox "You are running Xp or higher." #ElseIf MyWordVersion = 9 Then MsgBox "You are running 2000." #ElseIf MyWordVersion = 8 Then MsgBox "You are running 97." #Else MsgBox "I don't know what you are running." #End If
End Sub
Eddie
Aminc - 16 Sep 2005 17:38 GMT So does that mean I am stuck with no resolution?
 Signature AminC
> Burying an invalid statement inside an if statement does NOT get it past the > compiler! [quoted text clipped - 16 lines] > > Eddie Edward Thrashcort - 16 Sep 2005 21:13 GMT Can you manually set the compiler variable at module level for each version of Word that you want to compile in?
If not, you are stuck with distributing three or more versions of your macro, each with identical #if blocks but with a different compiler constant in each version.
Eddie
Aminc - 17 Sep 2005 00:27 GMT You know what Jean-Guy was right. All I have to do is code for the two different versions but compile it in Word 2003. It works! both for 2000 and 2003. The only limitation I am stuck with now is that I will always have to compile this program in 2K3 - no more 2K, but I guess I will have to live with it.
 Signature AminC
> Can you manually set the compiler variable at module level for each version > of Word that you want to compile in? [quoted text clipped - 4 lines] > > Eddie Jean-Guy Marcil - 17 Sep 2005 01:57 GMT Aminc was telling us: Aminc nous racontait que :
> You know what Jean-Guy was right. All I have to do is code for the two > different versions but compile it in Word 2003. It works! both for > 2000 and 2003. The only limitation I am stuck with now is that I will > always have to compile this program in 2K3 - no more 2K, but I guess > I will have to live with it. Phew! I thought I was going nuts in my office, thinking that my computer was special or something like that! If you remember, early in the thread, I asked why you wanted to compile code in 2000 when it contained 2003 stuff
Maybe I am too verbose and you never got to the part where I wrote:
"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."
Or, as I mentioned earlier: "Or are you, like me, one of those people who understands things really quickly if they are explained long enough? "
(In case the smiley isn't obvious enough, I am just kidding, I do not mean to insult you with that comment. I am writing it because, I am truly like that, sometimes very obvious stuff escapes me because I insist in focusing on one detail, thereby not seeing the full picture...)
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Aminc - 17 Sep 2005 08:17 GMT Yes. I agree that I missed your remark in that email. I guess it was because I simply could not comprehend not being able to compile in 97/2000 and the reason is majority of our customers use these two and 2003 is a minority. There are a lot of occassions where I will have to make minor changes (right on the user machine) and now I will lose that ability because majority don't have 2003. Anyway, being able to provide the solution is good enough for me at this point. Many thanks.
 Signature AminC
> Aminc was telling us: > Aminc nous racontait que : [quoted text clipped - 23 lines] > that, sometimes very obvious stuff escapes me because I insist in focusing > on one detail, thereby not seeing the full picture...) Jonathan West - 17 Sep 2005 11:21 GMT > Agreed Jean-Guy, but I guess I am not able to explain. Problem is that > InsertLineBreaks argument with the ActiveDocument.SaveAs is unavailable in > versions prior to 2003. So if I code to pass InsertLineBreaks:=True is > user > is running say 2000 or 97, I am unable to compile the program. You are quite correct, but there is a workaround.
Place all code that is Word-2003 specific in a separate module. Call it from the appropriate If-then or Select Case construction.
Do not attempt to compile the code in the VBA editor.
The code will run OK in Word 2000, because the module containing Word 2003 code is never called and therefore never compiled while in Word 2000. It is called and will compile fine in Word 2003.
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Michael Bednarek - 17 Sep 2005 13:06 GMT >Sure. I can do that... but problem is when I use InsertLineBreaks:=True (for >Word 2003), I cannot compile it in Word 2000 or Word 97 because that property >is unavailable. Shot in the dark:
Function WordVersion() As Single Dim wrdObj As Object
Set wrdObj = CreateObject("Word.Basic") WordVersion = Val(wrdObj.AppInfo(2)) ' Word Version
End Function (Found at <http://groups.google.com.au/group/microsoft.public.access.modulesdaovba/msg/eddf 2c0c21e549eb?dmode=source&hl=en>).
Then, in your main code:
If WordVersion = 11 Then #Const WrdVer = 11 End If ... ... #If WrdVer = 11 Then ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat, InsertLineBreaks:=True #Else ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat #End If
>> On Thu, 15 Sep 2005 13:28:04 -0700, "Aminc" >> <Aminc@discussions.microsoft.com> wrote in [quoted text clipped - 12 lines] >> Use Application.Build and If or Select Case to code for the different >> versions.
 Signature Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Jean-Guy Marcil - 17 Sep 2005 15:20 GMT Michael Bednarek was telling us: Michael Bednarek nous racontait que :
> On Fri, 16 Sep 2005 06:38:02 -0700, "Aminc" > <Aminc@discussions.microsoft.com> [quoted text clipped - 9 lines] > Dim wrdObj As Object >... I am not sure, but I have tried something like that before and found that it was impossible to declare your own Compiler constant. I took your code and twisted it around to test it in Word 2003:
'_______________________________________ Function WordVersion() As Single Dim wrdObj As Object
Set wrdObj = CreateObject("Word.Basic") WordVersion = Val(wrdObj.AppInfo(2)) ' Word Version
End Function '_______________________________________
'_______________________________________ Sub test()
If WordVersion = 9 Then #Const WrdVer = 9 'Word 2000 = 9 End If
#If WrdVer = 9 Then ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat #Else ActiveDocument.SaveAs FileName:=sDocName, FileFormat:=iFormat, InsertLineBreaks:=True #End If
End Sub '_______________________________________
So, under 2003, the Else statement should get executed, right? Or did I miss something?
But in fact, it is the If statement that gets executed, as if the value of WrdVer did not matter.
Or am I doing something wrong?
Finally, is there a reason for using:
'_______________________________________ Function WordVersion() As Single Dim wrdObj As Object
Set wrdObj = CreateObject("Word.Basic") WordVersion = Val(wrdObj.AppInfo(2)) ' Word Version
End Function '_______________________________________
instead of something like:
'_______________________________________ Dim WordVersion As Long WordVersion = Val(Left$(Application.Version, 2)) '_______________________________________
in the same procedure?
(I am not asking so much about the branching out, which maybe useful if you have many different module that have to check the Word version, but more about the CreateObject("Word.Basic") aspect of the function...)
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Michael Bednarek - 18 Sep 2005 03:51 GMT >Michael Bednarek was telling us: >Michael Bednarek nous racontait que : [quoted text clipped - 16 lines] >was impossible to declare your own Compiler constant. I took your code and >twisted it around to test it in Word 2003: [snip]
As I said, it was s shot in the dark. Now, it seems to me that constructs like If cond Then #Const myConst = expr Else #Const myConst = Not expr End If are illegal (Duplicate definition), and constructs like If cond Then #Const myConst1 = expr1 Else #Const myConst2 = expr2 End If
will cause both myConst1 and myConst2 be set to their respective expressions. Maybe this sentence in the Help file on the "#Const Directive" is responsible: "Conditional compiler constants are always evaluated at the module level, regardless of their placement in code."
I give up. Upgrade everyone to V-11.
>Finally, is there a reason for using: > [quoted text clipped - 20 lines] >have many different module that have to check the Word version, but more >about the CreateObject("Word.Basic") aspect of the function...) I just copied the code from the quoted source.
 Signature Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Fletcher James - 27 Sep 2005 01:50 GMT I deal with issues like this all the time. The easiest thing is to declare an extra variable as OBJECT.
Dim ww11 As Object
Then, you can say:
If Application.Version > "10.99" Then Set ww11 = Application ww11.SomePropertyOnlyAvailableInWord11 = ...
In other words, you're using late binding -- properties of "Object" variables aren't checked until they're called.
If it's a Document property, then simply declare:
Dim doc11 as Object
If Application.Version > "10.99" Then Set doc11 = ActiveDocument doc11.SomePropertyOnlyAvailableInWord11 = ...
and so forth.
 Signature Fletcher James President Levit & James, Inc.
(703)771-1549 MailTo:fjames@levitjames.com http://www.levitjames.com
>I have a program (DOT) running behind Msword via an application. One of the > automation is to save the active document using MS DOS With Layout format [quoted text clipped - 9 lines] > Does anybody know a workaround method where the same program can work for > all versions without major changes?
|
|
|