Help - Paste COM Excel Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Help - Paste COM Excel

03 Sep 2019, 13:43

Hi guys :mrgreen:

I have a little question about handling Excel with AHK. Is it possible to paste a variable directly into a cell?I know I can pass the value of the variable to the clipboard and paste, but if you don't prefer, can you paste a variable directly?

I tried and I couldn't (Message error: Unable to set the Paste property of the Worksheet class)

Code: Select all

Var_Call=1010101
xlApp := ComObjCreate("Excel.Application")
xlAppDown := -4121
xlApp.Visible := true
xlApp.DisplayAlerts := False
oxWorkbook := xlApp.Workbooks.Open("C:\Temp\Some_Plan.xlsm")
oExcel.Range("A1").Select
oxWorkbook.ActiveSheet.Paste := Var_Call
ShatterCoder
Posts: 84
Joined: 06 Oct 2016, 15:57

Re: Help - Paste COM Excel  Topic is solved

03 Sep 2019, 14:56

You are pretty close, just use the following:

Code: Select all

xlApp := ComObjCreate("Excel.Application")
xlAppDown := -4121
xlApp.Visible := true
xlApp.DisplayAlerts := False
oxWorkbook := xlApp.Workbooks.Open("C:\Temp\Some_Plan.xlsm")
xlApp.Range("A1").Value := "Whatever you want here"
xlApp.Range("A2").Value := VarToPaste
If you want to target a specific sheet/tab you would use change it to xlApp.Sheets("SheetName").Range("A1").Value := var
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Help - Paste COM Excel

04 Sep 2019, 13:15

ShatterCoder wrote:
03 Sep 2019, 14:56
You are pretty close, just use the following:

Code: Select all

xlApp := ComObjCreate("Excel.Application")
xlAppDown := -4121
xlApp.Visible := true
xlApp.DisplayAlerts := False
oxWorkbook := xlApp.Workbooks.Open("C:\Temp\Some_Plan.xlsm")
xlApp.Range("A1").Value := "Whatever you want here"
xlApp.Range("A2").Value := VarToPaste
If you want to target a specific sheet/tab you would use change it to xlApp.Sheets("SheetName").Range("A1").Value := var
Nice :D Really thanks for your help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Ralf_Reddings200244 and 96 guests