Windows().Activate works on every computer except one - vba

I have encountered a strange problem, I made macro about a year ago and it is being used every month without problems. Yesterday my boss told me, he cannot use it anymore, that it gives him some errors. I now tried the macro on 8 computers and the macro ran perfectly. Why is it that macro runs on everyone else's computer, except for my boss.
The line it breaks on
Windows("MyxlsbFile").Activate
And the error given is
Run-time error '9': Subscript out of range.

Whether or not you can leave off the file extension when calling (eg)
Windows("MyxlsbFile")
or
Workbooks("MyxlsbFile")
depends on whether the Windows Explorer setting "hide extensions for known file types" has been checked or not: if file extensions are shown in Windows Explorer then you must include the extension when calling WorkBooks().
I'm guessing this is the issue on the one PC where you have the problem.
Including the file extension always works (as long as there's no other error of course)

Related

Compiled Access Program Runs Fine on 7 Computers but Crashes on 3 others

I have written a rather complex application in Microsoft Access. It is split into front end and back end files. To protect my code, I have compiled it and saved it as a runtime .accde file, which I then changed to an .accdr file to ensure it operated as a runtime. I have created two versions of the application: one for those with 32-bit Office installed and one for those with 64-bit office. I have used Inno Setup to package the application, the data file, and other files such as the icon file, the license file, etc., into an installable package, which works just fine.
Among my team of 27 beta testers of this application, so far 6 have downloaded it, and I have tested it on four of my own computers. On seven of these computers, the installation works perfectly and the application runs with no problems.
On the computers of three of my testers, when they try to run it, they get this error message:
The expression On Open you entered as the event property setting produced the following error: Bad file name or number.
* The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
I'm pretty sure I know where the code is that's causing the problem, but cannot for the life of me figure out why the application crashes on those 2 computers but not on others.
The On Open event I suspect of causing the problem checks the linked tables, gets their connect string, then looks at the path for that string for the back end database. If it does not find it there, the procedure pops up a file selector dialog and instructs the user to find the data file, then it relinks all the tables.
If anyone could point me in the right direction to fixing this problem, I would be extremely grateful.
This is typically caused by a reference labelled as MISSING.
You have two (three) options:
Run the application on the offending machines with a full version of Access that lets you debug the code
Create a small test application that lists and verifies the references you use, and run this on the offending machines
Remove those two customers
Thanks to all the contributors here. Because of these folks and additional online research, the latest answer I can find is this:
This error occurs on a small percentage of computers on which the app is installed, and no one has yet figured out why, what causes it, or how to fix it. The workaround is to install the 2013 version of the Access runtime, as later versions will still cause the problem.
At least one of the offending computers is running the Click-to-Run version of Office. Still gathering information, but that's the status as of now.

Secure VBA Excel Addin Code

I have an Excel addin, developed in VBA, deployed on the network.
The addin reads from an Oracle database, and pastes tables in a new worksheet, which will also contain a button (triangle shape) to refresh the table.
Everything works great, but I must protect code with password.
When i do, the following error appears on some machines:
Compile error in hidden module: Main.
This error commonly occurs when code is incompatible with the version, platform, or architecture of this application.
Although it compiles perfectly when unlocked.
On other machines it requires VBA password on close, even though i have nothing of the sort defined under close event.
I am hoping to secure my code, without running into above problems.
Any suggestions are appreciated.
I know of two situations in which this error occurs:
1: 32bit vs. 64bit issues (already mentioned in the comments). If you've developed a 32bit addin and try to deploy/use it within a 64bit Excel, then your quoted error message will appear.
2: Missing references.
I think the second option is more likely to be the cause of the problem, because usually all client PCs in a company will have the identical version of MS Office installed and this error occurs only on some machines.
So I suggest to check your references. In the VBA-Editor (Alt+F11) go to tools --> references and note down any ticked modules. Then compare this to a client where the error is occuring (go to client PC and repeat the procedure).
If the ticked modules don't match between development and client PC, this is most likely the cause of this issue. You might also encounter modules with a "MISSING" written in front of their name on the client PC. In this case, remove the tick from the missing module and try to execute your addin.
If it works flawlessly you should be good to go, if not you'll have to manually install the missing modules on the clients PC.
Hope this will help you.

Excel cannot find my Macro

I have a Worksheet.Activate macro for pasting information that has been working for over a year now. I have multiple users using the macro with no problems. Recently one user is having this error whenever they paste into this worksheet that activates the macro:
Run-time error '1004': 'C:\Users\xxxx\Documents\Master_Macros.xlsb' could not be found. Check the spelling of the file name, and verify that the file location is correct.
They have never had this issue before and as far as I know he hasn't done anything abnormal. The macro is located in the typical XLSTART folder, not the Documents folder. The macro file also includes other macros that are executing perfectly fine for this user. Excel is suddenly looking for the macro file in the Documents folder for this one Worksheet.Activate macro. I have spent some time googling, and I don't know if it is my keyword choice or what, I cannot find a solution.
The macro is run using this line:
Application.Run ("Master_Macros.xlsb!'C_Tool_Paste_Window.CTool_LineFix'")
Any help would be appreciated!
I had similar problem when I installed Service Pack.
If the users are accessing files from different computers,
make sure they all have same service pack installed

'File Not Found: VBA6.dll' Error - Strange Behaviour

I am running Windows 8 with Office 2013 (64-Bit). I am trying to continue developments in VBA in Excel that I started with Office 2010 (32-Bit). I am aware of the necessary 64-Bit alterations however I am receiving confusing configuration errors.
Here is the problem:
If I create a new Excel file and VBA project; all my VBA code functions correctly. No problems.
If I open and use a macro from a file that was developed/used in Office 2010 previously, I receive a "File Not Found: VBA6.dll" error message.
Once I start receiving the message, I receive it on all VBA macro's; even the new ones that (not more than 30 seconds) previously worked fine.
If I then re-create a new Excel file and new VBA Project, that individual piece of new code works fine. No problems - until I run code in one of the 'error files'. The fault then spreads into my new developments.
It's as if Excel is getting its references confused but every time I check them (on good or bad files) they are always exactly the same.
Note:
None of my references are missing.
I don't have VBA6.dll on my system; I have VBA7 and the 'Visual Basic for Application' reference refers too 'C:\Windows\SysWOW64\msvbvm60.dll'
There are two other 'Visual basic for Application' references on the list but it wont let me change them
It works on new files without VBA6.dll so I assume it isn't required?
I have checked for and installed all the latest Windows updates.
What should I do to troubleshoot this problem?
If you think I need VBA6.dll, is that because the referenced libraries use it?
If so then why are they not using VBA7?
And why does it work correctly before opening an old VBA6 file? Does Excel suddenly decide all files must use VBA6 just because one file did previously?
Anything to cure me of my confusion is much appreciated,
Best regards
EDIT: I almost forgot to mention;
When I try to debug the error after receiving it, Excel crashes (every time).
I also sent a 'bad file' to a colleague who [with the same system configuration] hasn't yet received this problem - and they also received the error. Suggesting it is something wrong with the files?
EDIT 2:
The problem is not yet resolved. I hope the downvote will not hinder my chances of an answer.
I have also tried re-registering libraries but nothing has changed.
If I open a 'bad file' I can add new Macros and they work fine; but the second I run an existing Macro and receive the error, the new Macros do not work either.
The error was caused during Office 2013 (64-bit) installation. The VBA7 DLL was not registered correctly so I had to open regedit and manually input the correct filepath in both
HKEY_CLASSES_ROOT\TypeLib{000204EF-0000-0000-C000-000000000046}\
6.0\9\win32
4.2\9\win32
Replacing the 'C:\Windows\SysWOW64\msvbvm60.dll' data value (mentioned in the question) for Visual Basic for Applications to the VBA7 DLL filepath. Which on my system is:
C:\Program Files\Common Files\Microsoft Shared\VBA\VBA7.1\VBE7.dll
All files now work; I hope this solves the problem for anyone else in the future.

Word error when processing multiple documents

Right now we have a program that opens all of the word files in a folder and adds some information to the footer. After switching from Windows XP and Word 2003 to Windows 7 and Word 2007 we have started getting the following error:
Run-time error '5096':
EOALPHABETICARABICARABICABJADARABICALPHABAHTTEXTCAPSCA
(c:\Users...\Content.MSO\8BE508C6.docx)
It occurs at random in any of the files (you can be 10 files in or 100). I thought that it might be a problem with the files being on a network drive so I modified the program to copy each file locally first, add the footer to that copy, and then copy it back out to the network. However, that didn't seem to work. I'm looking for any suggestions on how to fix the problem or possibly rewrite the solution. However, I need to keep the solution in VBA since this app is part of a bigger suite which in not ready for a .NET re-write.
As it turns out I was able to workaround this problem by copying the word files locally, running the main code on the local copies, then copying them back out to the network. It didn't seem to be working at first because the user's machine on which I tested it did not have the most recent version of the program.
Adding this note for those still looking for answers to this error...
I have a macro that creates several docs from one that is open based on sections in the main document.
I was getting the Run-time error '5096' and was an able to find any solutions that worked.
Upon further examination while debugging the code I discovered that while pulling data out of the main doc and building a file name that there was a carriage return after the file name and before the extension. After adding a replace statement to remove carriage returns I am able to process documents all day without an error.
I have found that the error is caused by the total number of characters in the file name is too long. This usually occurs when manipulating file names and the full path is set in the variable. I will manually chop pieces out of real long names to force it to work.
I suppose if I were smart, I'd move into the directory and just deal with the file names without the directory prepended to the name.