I posted a new topic becaus my old topic seems to have run dry (https://autohotkey.com/boards/viewtopic ... 33#p183033, post from 27th october 017)... I have a freshly generated workbook (not saved, it is generated by another programm which gives me a workbook with data I searched for). Some of it's cells have to be formatted. Then I export this workbook to a utf8 txt file which I read with autohotkey.
My problem is to connect to the workbook. I also tried to run an excel macro (stored in my personal workbook), but nothing works. I searched the forum without success. I tested to generate a new workbook using com. That worked. I succeeded in exporting the workbook to utf8 using com. But I could not run the macro.
Normally when I generate a new excel workbook by com my personal worbook is opened and I have access to my personal macros. When the generated workbook appears my personal wokbook does not...so I cannot get access to my macro.
Here is my ahk code to test getting access to the workbook:
This is the macro code I recorded in excel:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #F12:: WinWait, Microsoft Excel - Mappe1 WinShow, Microsoft Excel - Mappe1 WinActivate, Microsoft Excel - Mappe1 ;IfWinActive, ahk_class XLMAIN oExcel := ComObjActive("Excel.Application") oExcel.Run("PERSONAL.XLSB!liste_formatieren") oExcel := return
Running the macro manually in excel by works fine! The cells are formatted to "5.11.17 13:45" but running the script via ahk it throws an error on the NumberFormat. I read MS's documentation about the possible formats but none of my tries ("d.m.yy hh:mm" etc.) worked.
Code: Select all
Sub export2utf8() ' ' export2utf8 Makro ' ' Tastenkombination: Strg+e ' Columns("E:H").Select Selection.NumberFormat = "d/m/yy h:mm;@" Columns("A:H").Select Columns("A:H").EntireColumn.AutoFit ActiveWorkbook.SaveAs Filename:= _ "C:\Users\UserName\Documents\ListeFormatiert.txt", FileFormat:=xlUnicodeText _ , CreateBackup:=False Range("A2").Select End Sub
Can someone give me a hint?
Thanks a lot!