12-04-2019 10:50 AM - edited 12-04-2019 10:55 AM
Hello,
I am running into an issue when calling Excel macros with Labview. Some background:
Software:
LabVIEW 2018 32-bit
MS Excel 2013 32-bit
I have an Excel workbook that contains several macros written in "Excel 4.0 Macro". These macros involve copy and pasting sets of data numerous times. (Please see following code snippet for an example. The actual macros contain a lot more copy and paste statements and moves the data throughout different worksheets.)
Excel 4.0 Macro Example
MacroA(a)
=ACTIVATE("ExcelWorkbook.xls")
=WORKBOOK.SELECT("SHEET1","SHEET1")
=FORMULA.GOTO("RANGE")
=COPY()
=WORKBOOK.SELECT("SHEET2","SHEET2")
=FORMULA.GOTO("RANGE")
=PASTE.SPECIAL(3,1,FALSE,FALSE)
=RETURN()
These are currently run by an operator using keyboard shortcuts. The goal is to automate the running of the macros with Labview using Microsoft Excel 15.0 Object Library Version 1.8.
I am not sure how to use Labview to call the "Excel 4.0 Macro" macros directly. So I wrote a VBScript file in the workbook with functions that call the "Excel 4.0 Macro" macros.
VBScript Function Example:
Sub Run_Macro_4.0()
Application.Run ("MacroName")
End Sub
Labview will call the VBScript functions to run the "Excel 4.0 Macro" macros.
This all works fine, except I get the following dialogue when running the macros through Labview:
"We couldn't free up space on the Clipboard. Another program might be using it right now"
The dialogue pops up intermittently. I ran one particular macro several times through Labview. Sometimes I get the dialogue pop up a few times during one call, sometimes not at all. The pop ups are not acceptable as the system needs to be automated without the need for an operator.
Has anyone else experienced a problem similar to this? If so, is there anyway to just bypass the dialogue?
I will end with a screenshot of my block diagram for my simple Run Macro with Labview utility.
Thanks for your time
Gabe
12-04-2019 11:05 AM
Hi Gabe,
Could you include a command to clear the clipboard at the end of every macro?
Maybe something like:
Application.CutCopyMode = False
This may break the clipboard reference that Excel is holding onto.
12-04-2019 11:17 AM
csIowa,
Ah, just tried this approach but still get the pop up. I see the dialogue in the middle of a macro run so I guess clearing at the end doesn't help.
Sub Run_Macro_4.0()
Application.Run ("MacroName")
Application.CutCopyMode = False
End Sub
I also tried clearing the clipboard before a macro run. Still get the pop up.
Sub Run_Macro_4.0()
Application.CutCopyMode = False
Application.Run ("MacroName")
Application.CutCopyMode = False
End Sub
Gabe
12-04-2019 11:44 AM
Have you tried the solutions posted here?
What other applications do you have open while running these programs? Is there a specific application open when the dialog does come up?
12-04-2019 12:10 PM
12-05-2019 10:09 AM
RMowatt,
My program was installed on a bare Win10 PC. Only apps installed are LabVIEW and its drivers, MS Office 2013, and Notepad++. No other apps were open when macro runs. Just standard background Win10 processes.
Ran sfc /scannow, disabled addons, and rebooted as suggested. No luck.
I will try other solutions but my last resort will be to execute each process not required for Windows to try to find a conflicting application.
==================
Ben64,
I will try to add a delay between copy and paste iterations. Be back shortly.
Thanks
Gabe
12-05-2019 11:26 AM
Ben64,
Great suggestion. I added a 2 second wait between copy and paste iterations. I did not get the dialogue after running the macro ~10 times. I did get a different dialogue stating "Cannot open clipboard" but it only happened once.
So macro is much more stable. Just need to verify integrity of data.
Looks like the problem was actually happening in the "Excel 4.0 Macro" level and not VB and Labview calling it. Even though functions are called sequentially, clipboard falls behind?
For now I will implement the delay in all the macros and do more intensive testing.
Thanks,
Gabe