PDA

View Full Version : Code wonīt work with Win XP and Win Server



Cederbusch
03-07-2012, 07:16 AM
Hi. My first question here. Iīm a newbie to VBA, not English native speaking, so please bear with me.

Iīve built a code that works fine with Win 7. But in Win XP and both Win Server 2003/2008 (thin clients) it will give me an error saying that it canīt find the objects.

First it didnīt seemed to like code like:
TextBox1 = Date

So I removed that bit. Then it complained over something else. But if I try to execute an older document with basicly the same code but it accepts.

What kind of code or objects isnīt compatible between Win 7 and XP?

Help would be very nice. Otherwise code worth a weeks work is useless :banghead:

Cederbusch
03-07-2012, 08:25 AM
Iīve got access to a desktop viewer running against Windows Server 2003 and tried to run my code.

See attached picture. The message is in Swedish but says something like "Compile error: canīt find Object or library".

Whatīs up with that? :dunno

Frosty
03-07-2012, 09:52 AM
Hmm, I suspect this will be the same as another recent post: if you don't explicitly "dimension" (dim) and "type" (as String, as Date, as Integer, etc) variables in your routines, you are forcing VBA to guess what you want when the macro runs.

As you go up in operating systems/office versions... there are more choices VBA has to guess. In some cases, it will not guess the same as it once did.

This is, broadly, what you are dealing with here, most likely.

Does the following work?

Msgbox CStr(Date)

What about
Dim sDate as String
sDate = Format(Date, "mm dd yyyy")
Msgbox sDate

Also, you may wish to check, in the VBA window, Tools > References and see what (if any) references are missing or seem strange. Compare those references in your macro project to the references which show up in a blank new document, created today. List those out, if you would...

Cederbusch
03-08-2012, 01:54 AM
All references are there. None of the two codes work when I run it trough Windows Server 2003. Seems to be unable to find the object Date. See picture.

The thing is that I now tried two very similiar documents. Both are .docm. Both have the exact same vba-code in the Document_Open routin. One document runs perfectly, the other one (the new and more complex one) doesnīt!! Gives an error.

I canīt figure out why both of them doesnīt work and what the difference between them is.

Have I missed something fundamental with VBA? If I write some code into sub Document_Open() that, lets say, pops up a messagebox and then nothing else, would the document then read all the other code even though it is not instructed to run the code? Could it be that something inbedded in the code in other parts of the document is the real issue here?

This drives me crazy! :banghead:

Cederbusch
03-08-2012, 03:30 AM
This is now solved. Finally. Still donīt know the reason for the error message. I just copied all the code into a new template and voila! It worked. Something was terrible wrong with just that document.

Well, turned out not to be a VBA issue. :think:

Frosty
03-08-2012, 07:06 AM
Ahh, well that's good.

I wonder if VBA.Date would have worked on the "corrupt" template.

In any event, it is a good idea, especially when switching operating systems, to reset your code base by exporting and importing into a "clean" document. Especially if the original code template has been through many versions.

One other tip on development in different environments: don't ever write code in a terminal services session and expect it to work anywhere else. There are lot of quirks there, do it is always better to save code templates on a local machine.