To stop Excel updating calling Excel from AutoHotkey via COM - excel

Let an handle to our currently active Excel sheet is created in an .ahk script through
Xl := ComObjActive("Excel.Application")
and then some values are managed, as instance through
Xl.Sheets("Book1").Range("K2:K239").Copy
It looks like AutoHotkey allows for using VBA syntax to interact with Excel workbooks and sheets, but what if I wanted to stop the Excel autoupdating function like I would do in VBA?
Application.ScreenUpdating = False
I've tried something like
Xl.Application.ScreenUpdating = False
and
Xl.ScreenUpdating = False
but AutoHotkey returns error in both the cases.

I think all you are missing is a colon... Xl.ScreenUpdating := False

Related

How to disable or auto-select 'OK' on VBA dialogs using Python (Application.DisplayAlerts = False does not work)

I have a script that opens an Excel spreadsheet and then goes to a specific sheet before running a macro. The problem is that this macro brings up different dialog boxes which require user input - I am trying to automate the process. I have tried to get rid of these boxes by using the following code:
import os
impor win32com.client
xl = win32com.client.Dispatch('Excel.Application')
xl = DisplayAlerts = False #Supposed to disable alert/messages/dialog boxes
wb = xl.Workbooks.Open(os.path.abspath('Test.xlsm'), ReadOnly = 0) #Opens spreadsheet
wb.Worksheets('Assets').Activate() #Activates correct sheet
wb.Application.Run('MxRunAction') #Runs macro
wb.Clost(True)
I have read on many threads that:
Application.DisplayAlerts = False
is supposed to fix this problem, yet this seems to do nothing if I substitue Application with xl for my case. Am I using it properly in this sense?
That would be the Application need to be closed
xl.DisplayAlerts = False

Excel Interop - Display full screen error?

I'm using Excel Introp for a .net application to embed an Excel workbook in a windows userform.
excApp.Visible = False
wb = excApp.Workbooks.Open(directOpenPath) ' , [ReadOnly]:=False, IgnoreReadOnlyRecommended:=True)
wb.Saved = True ' necessary to prevent Excel has stopped working error and to not actually do a save
hwnd1 = CType(excApp.Hwnd, IntPtr)
SetParent(excApp.Hwnd, pnlExcel.Handle)
SendMessage(excApp.Hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
MoveWindow(hwnd1, 0, 0, pnlExcel.Width, pnlExcel.Height, True)
excApp.Visible = True
There are ActiveX buttons on the worksheet that work fine when I open using the above code.
However, it is my desire to make the object look less like Excel so I wanted to hide the ribbon, formula bar, etc.
I added the line: excApp.DisplayFullScreen=True. Upon doing that, clicking on a button no longer kicked off the associated macro. Additionally, I could no longer click on any cell in the worksheet. This seems like odd behavior but I have traced it down to the DisplayFullScreen line.
Also I am trying to include the following:
excApp.ActiveWindow.DisplayWorkbookTabs = False
excApp.ActiveWindow.DisplayHeadings = False
excApp.ActiveWindow.DisplayGridlines = False
But I get a object not set to reference error. If I add excApp.ActiveWindow.Activate, the worksheet "locks up" again and I can't click on any cells.
Any ideas?

How to re-order worksheets using python's xslxwriter

I am using xslxwriter to produce a excel spreadsheet, and I am wondering if there is anyway I can re-order my worksheets in my workbook.
I have tried to change the index, but this doesn't seem to work (index doesn't seem to alter the order).
Any idea if this can be done with xslxwriter, or is there another module I should be using?
I have found a workaround, unfortunately not in the xslxwriter module but the pywin32 addin.
Using the following you can reorder your sheet "WorkSheetToMove" in an Excel spreadsheet:
excel = win32com.client.Dispatch('Excel.Application')
excel.Visible = True
wb = excel.Workbooks.Open(Filename="excelyouwanttoreoder.xslx", ReadOnly='False')
for worksheet in wb.Sheets:
if worksheet.Name == "WorkSheetToMove":
worksheet.Move(Before=wb.Sheets("Sheet2"))
wb.Close()

programming for excel with foxpro (or any suggestions)

I have a macro in excel that works.
Sub jim()
Range("$A$1").CurrentRegion.Select
Selection.RowHeight = 13
Selection.Font.Bold = True
…etc.
If I open a csv and run this macro it selects the seen data and then later does stuff to it.
So I made a foxpro program to do the same.
When I try to run in foxpro, I get a variable not found error.
local oExcel, oSheet
oExcel = CreateObject([Excel.Application])
oExcel.Visible = .T.
k:\wellcarestuff\All Data Files\"+ALLTRIM(xlfiles(1,1))
osheet = oexcel.workbooks.open("k:\wellcarestuff\all data files\20131210_CT_TransportationAddresses.csv") <<<=== it opens and shows the sheet here
Range("$A$1").CurrentRegion.Select <<<?=== get an error here?
Is the var it wants the current osheet?
On the line with the path, it looks like you are missing the beginning quote marks so it things that k:... is a variable. Should be:
"k:\wellcarestuff\All Data Files\"+ALLTRIM(xlfiles(1,1))
Try that and see if it works.

How to add more than 3 sheets to an excel workbook from within MATLAB

How do I add more sheets to an excel workbook from within matlab?
I set up the workbook like so (based on code I got from someone else's post in this forum):
%# create Excel COM Server
Excel = actxserver('Excel.Application');
Excel.Visible = true;
%# create new XLS file
wb = Excel.Workbooks.Add();
wsheet=1;
wb.Sheets.Item(wsheet).Activate();
That's fine. Then later on inside the loop I open a new sheet after so many loops:
...
if loop==sheetlimit,
wsheet=wsheet+1;
wb.Sheets.Item(wsheet).Activate();
end
This works up to sheet 3. But when wsheet=4 I get this error message:
??? Invoke Error, Dispatch Exception: Invalid index.
Error in ==> filename at 97
wb.Sheets.Item(wsheet).Activate();
Appreciate any help. Thanks.
I don't know Matlab but I would be surprised if wb.Sheets.Item(wsheet).Activate(); is actually adding any new worksheets. Most likely it is selecting / activating each worksheet in your wb workbook and your default Excel template has three worksheets. Hence why it errors when it gets to more than three.
Something like this might add a new Excel worksheet:
wb.sheets.Add();
Aargh - comment formatting completely messed up - I'll re-enter it as an new answer
Yes wb.sheets.Add(); will work. You can query the available methods of an interface like this:
methods(wb.sheets)
which gives:
Methods for class Interface.000208D7_0000_0000_C000_000000000046:
Add FillAcrossSheets PrintOut addproperty events loadobj set
Copy Item PrintPreview delete get release
Delete Move Select deleteproperty invoke saveobj

Resources