Why does Excel VBA calling an add-in function crash Excel? - vba

I am running 32-bit Excel 2010 (Windows 10.1) with an add-in loaded (which I developed). I need to call one of the add-in functions (I will call it changeText) from VBA.
I've written the following VBA code behind one of the worksheets:
Sub MakeChange()
Dim result As String
result = Application.Run("changeText", "teststring")
Debug.Print result
Debug.Print "Complete"
End Sub
and assigned this Sub to a button on that worksheet.
If I run this function directly from within the VBA editor it works fine every time and returns the correct result to the Debug window.
If I call the function from within Excel by pressing the button, I get a Type Mismatch error (via a message box) the first time. If I then press the button again, everything hangs and the only way out is to kill the process.
If I move the function to a workbook-level module, more or less the same thing happens - I get a Type Mismatch error on the Application.Run line to which I click 'End', then the same again on the second click but this time the application hangs after pressing 'End'.
The add-in is mature and the function being called works perfectly when called directly from within Excel or otherwise invoked by the add-in. The XLL function being called takes a string and returns a string.
Does anyone have any idea what could be happening here, and in particular why the application is crashing?

Related

Excel VBA Application.Interaction

I have some macro code that runs in my BeforeSave event and before it runs I am using the following line.
Application.Interactive = False
When saving the file normally everything works fine. If I select multiple tabs via ctrl/click and try to save I get an error which reads.
Run-time error '1004':
Method 'Interactive' of object '_Application' failed
It seems to me that the Interactive property is not available to set when you have multiple sheets selected. The reason I want to select several sheets and not the entire document is I am doing a save as and selecting PDF.
Any ideas why this would not work or what could be use in place of Application.Interactive?

Cannot run the macro. The macro may not be availabe in this workbook

Having an issue with VBA error 'run time 1004'. Using the following code. The macro is called from a button in Row 5, hence the subtraction. There are other buttons in rows 6, 7, 8 etc. all calling the same macro (to subsequently call a specific userform), hence the variable.
Sub Export()
i = RowNumber - 4
Reinstated = "ReinstateR" & i
Application.Run Reinstated
End Sub
The macros 'ReinstateR1', 'ReinstateR2' etc. are all stored in a separate module.
Sub ReinstateR1()
'Macro function etc.
End Sub
For some reason, though, when I click the button, I get the following error message:
"Cannot run the macro 'ReinstateR1'. The macro may not be available in this workbook or all macros may be disabled."
All macros are enabled, the macro is in the same workbook, etc. Trust centre settings are set to disable all macros with notification, etc.
I'm stumped. I can call the macro without the variable, but that's not the point...
If you have a module with the same name as a routine it contains, you need to prefix any call to it using Application.Run with the module name as well (or change the name of either the module or the routine), so in this case it's:
Application.Run "Reinstater1." & Reinstated

VBA Excel Not Responding when opened through QTP

Action performed using QTP script --> After opening the Spreadsheet abc.xlsm ,when the Search macro is invoked, the search window opens and by providing search criteria in it when I hit "Enter" button, the Excel goes into Not Responding state (macro is not run completely) until the server itself gives the following:
408 timed out request
When the same above action is performed by manually invoking the spreadsheet. it works perfectly fine.
below is the code i am using to open the spreadsheet and performing Search macro run..
Dim wShell
Set oexcel= CreateObject("Excel.Application")
oexcel.Application.Visible=True
Set obook=oexcel.Workbooks.Open("C:\abc.xlsm")
Set osheet=obook.Worksheets("Search")
oexcel.Application.Run("search") 'This is the Search macro that we are runnig
wait 2
Window("search").Activate
Set wShell = CreateObject( "WScript.Shell" )
wShell.SendKeys ("%") ' this is the input search criteria
wShell.SendKeys "{TAB}"
wait 2
wShell.SendKeys "{ENTER}"
wait 5
After the above line of code is executed,the excel goes into not responding state.
However the same code works perfectly fine for another spreadsheet say xyz.xlsm for the same search macro. And it always works well manually.
XLSX/XLSM is not supported by UFT. Yea I ran into this as well. Real pain in the neck, but that's just the way it is. Just use old-style .XLS files and it will work just fine.

Excel Macro opens with run time error 32809

I have an Excel Macro Enabled workbook that I created on Excel 2013. The workbook's macros work well with my computer but does not work on some other computers even if they are using Excel 2013. Works on 7/10 computers I tried both on windows 7 and 8. When I send it to someone's computer that does not work this is what happens:
They open the workbook and once the user clicks "enable content" the workbook errors out "run time error '32809': Application-defined or object-defined error"
debug shows it getting stuck on 2nd line of code below:
private sub workbook open()
Worksheets(1).OLEObjects("ComboBox21").ListFillRange = "impacts"
**Worksheets(2).OLEObjects("ComboBox21").ListFillRange = "yesnoo"** This line errors
if I comment out these two lines, the workbook will open but the combobox21 on worksheet(2) gets renamed to combobox22 and does not work but the first combobox on worksheet(1) loads and functions fine.
I would like to add that if I comment out the lines
Worksheets(1).OLEObjects("ComboBox21").ListFillRange = "impacts"
Worksheets(2).OLEObjects("ComboBox21").ListFillRange = "yesnoo"
I get the error now that "Can't exit design mode because control ' dattimepicker21' cannot be created
I found and fixed the problem, the machines that were not working were missing MSCOMCT2.OCX
http://answers.microsoft.com/en-us/office/forum/office_2013_release-excel/date-picker-dropdown-in-excel-2013/71decdcd-6cc6-4a70-b1ab-20294a2a315a

Application.Run stops the current code

I am opening 2 separate instances of excel and Application.run is working to run a macro in my other workbook but it stops all the code below it even when I close out that application.
The problem is that inside of your macro you have an "end" which is being stopped at which stops all code from running even the parent who is executing the child. Replace the "end" with an "exit".