Jump to content
Hlaurent

Excel - Filling cells from radio button groups on autoit form - help me please

Recommended Posts

Hlaurent

hi. i tried so much and at the end here i am writing this:

my problem is that i cant find a way to assign "WRITE'EM" button to send radio group values (as text or number) to a specific cell (column(x) and already selected row(selected y)) in already opened (active excel document) .

process:

WHO button :  Entries to the excel table will be one after another. So i will select the first cell manually. then i start gui and  I will press WHO. (i made it already and it works. so help that i need is not here) 

SHEET, DAYS, STARTS, WEEKEND selections will be clicked by user (me) and WRITE'EM button should send all radio-button values at once to the cells (selected row number(y) which i chose as i activate WHO button.

for example : SHEET VALUE = 43 should fill "43" cell(6,$y)
and $y is active cell row number. 

DAYS Value = 30 should fill "30" cell(7,$y)
STARTS value = "15.06.2015" cell(8,$y)
WEEKEND value ="YOK" cell(9,$y)
 

as i hit the WRITE'EM

tumblr_nop61lhUdT1rt0f83o1_500.jpg

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\hloo\Documents\koda_1.7.3.0\Forms\staj_go.kxf
Global $Form1 = GUICreate("Form1", 398, 287, 445, 275)
Global $Edit1 = GUICtrlCreateEdit("", 48, 24, 329, 73)
GUICtrlSetData(-1, "Edit1")
Global $Button1 = GUICtrlCreateButton("WRITE'EM", 96, 216, 105, 33) ; sends all radio button group values to specific cells at once
Global $Button3 = GUICtrlCreateButton("WHO", 8, 24, 33, 225)
Global $Group1 = GUICtrlCreateGroup("SHEET", 48, 112, 57, 81)
Global $Radio1 = GUICtrlCreateRadio("22", 56, 136, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Radio2 = GUICtrlCreateRadio("43", 56, 160, 49, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group2 = GUICtrlCreateGroup("DAYS", 112, 112, 65, 81)
Global $Radio3 = GUICtrlCreateRadio("30", 128, 136, 33, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Radio4 = GUICtrlCreateRadio("60", 128, 160, 41, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group3 = GUICtrlCreateGroup("STARTS", 184, 112, 105, 81)
Global $Radio5 = GUICtrlCreateRadio("15.06.2015", 200, 136, 81, 17)
Global $Radio6 = GUICtrlCreateRadio("29.06.2015", 200, 160, 81, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group4 = GUICtrlCreateGroup("WEEKEND", 296, 112, 81, 81)
Global $Radio7 = GUICtrlCreateRadio("VAR", 312, 136, 49, 17)
Global $Radio8 = GUICtrlCreateRadio("YOK", 312, 160, 49, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

         Case $Button3
Local $i = 0
; take information from active excel, select 2 cell and send it to autoit form by simple keyboard keys - done
Do
   WinActivate("Microsoft Excel") ; go to Excel
                WinWaitActive("Microsoft Excel")
                Sleep(500)
                Send("+{RIGHT 2}")
                Sleep(500)
                Send("^c")
                Send("!{TAB}") ; back
                Sleep(500)
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("^a")
                Send("^v")
Until GUICtrlRead($Button3) = $i
 ; copies 


;Case $Radio1 ------------------below, that i couldnt manege to make it right
;   if $Radio1 = 1 then
;     Local $belge = "22"
;   ElseIf $Radio2 = 1 then
;     Local $belge = "43"
;   Case $Radio3
;     if $Radio3 = 1 then
;     Local $gun = "30"
;   ElseIf $Radio2 = 1 then
;     Local $gun = "60"


;Case $Button1
;.cells($i, $j).value = $belge ----------------- this part that i need help most.
           EndSwitch

WEnd

i put ";" marks to my failures. if you want to help this code-poor person which is happen to be me, please don't bother to write all. just a clue would be enough.

ps: i don't need MSGBOX in any section of this. But all i find as function in examples is msgbox. 
i dont need clean excel book to open. i have students information in existed excel file and all i need to automate some specific cells again and again.

thx thx thx.

 

sry i forgot  here is the piece of excel file that i work on.

https://docs.google.com/spreadsheets/d/1Gins_bYw143qn_voZQBsCAwPMQDbwDyttg1l_qKZ5HU/edit?usp=sharing

 

Edited by Hlaurent

Share this post


Link to post
Share on other sites
MikahS

Have a look at the Excel UDF.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
Hlaurent

. with quote, answer is below 

Edited by Hlaurent
didn't see the quote thing at first

Share this post


Link to post
Share on other sites
Hlaurent

Have a look at the Excel UDF.

i looked there. thx for quick response btw. But that is not the answer to my deadlock.

i need an example which uses _Excel_RangeWrite whom range is consist of already selected row number and constant x for radio groups.

 

Share this post


Link to post
Share on other sites
MikahS

It looks like your trying to use dot notation on an object without a MS excel object.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
l3ill

Hi,

 as MikahS Mentioned you will eventually have to get cosy with the excel UDF.

But in the mean time I threw together a down and dirty example that I think might answer your question of how to get your GUI variables; radio buttons etc into an excel sheet.

This is mostly CCP' ed from the helpfile with some small changes to illustrate the point.

#include <GUIConstantsEx.au3>
#include <Excel.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    Local $idSend = GUICtrlCreateButton("Send", 200, 200, 85, 25)
    Global $Radio1 = GUICtrlCreateRadio("22", 56, 136, 49, 17)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop
            Case $idSend ;---------------Send Button Calls Case $iDSend----------Case calls Function named ""SendToExcel()"" below
                SendToExcel()

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example



Func SendToExcel()

    ; Create application object and create a new workbook
    Local $oAppl = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookNew($oAppl)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oAppl)
        Exit
    EndIf

    ;--------------------------------------------------
    $radioVar = GUICtrlRead($Radio1)

    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $radioVar, "A3")

    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

EndFunc
Edited by l3ill
effed up

Share this post


Link to post
Share on other sites
Hlaurent

Hi,

 as MikahS Mentioned you will eventually have to get cosy with the excel UDF.

But in the mean time I threw together a down and dirty example that I think might answer your question of how to get your GUI variables; radio buttons etc into an excel sheet.

This is mostly CCP' ed from the helpfile with some small changes to illustrate the point.

 what a active forum! thank you firstly. 

in your example you decided the source cell right? = A3.  

$radioVar = GUICtrlRead($Radio1)

    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $radioVar, "A3")

but i need something like this: 

i click -for randomly example- D36 cell on already open excel doc.

can i have this :

$activeCellRow = _excelGetActiveRowValue() ; which i made up - which is my question
$constantColomn1 = 6
(then your way)

$radioVar = GUICtrlRead($Radio1)

    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $radioVar, "$oExcel.activesheet.Cells( $constantColomn1, $activeCellRow)") <<<----instead of "A3"

ok?

i need variables comes from active-manually-clicked cell's row information instead of determinative "A3" or any thing like that. 

so i need to automate the cell ingredients. x and y from outside of user entry. 

 

Edited by Hlaurent
"column is first" fix

Share this post


Link to post
Share on other sites
MikahS

Quick example of how to get the active cell using dot notation. Don't know if it's a very elegant solution, but it gives you an idea of what to search for etc.

#include <Excel.au3>

HotKeySet("{ESC}", "Quit")

Local $oWorkbook = _Excel_Open()

_Excel_BookNew($oWorkbook)
_Excel_SheetAdd($oWorkbook)

Local $oRange = $oWorkbook.Application.Activecell.Address

Local $oAddress = StringReplace($oRange, "$", "")

MsgBox(0, "", $oAddress)

while 1

WEnd

Func Quit()
    _Excel_Close($oWorkbook)
    Exit
EndFunc

 


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
l3ill

Sorry, I am not positive what you are going for but as mentioned before you will have to get in to the help file and play around with the examples and find the function closes to what you want to achieve and then change it accordingly.

That's how I learned :D the little bit I know...

Specifically I would start with _Excel_RangeRead

The keywords you mentioned seem to be going this direction.

BTW: There are other ways of directing data into the sheet besides A1 Range; array, 2D array, Range Object...

Edited by l3ill
msp

Share this post


Link to post
Share on other sites
l3ill

Very Cool MikahS !

So using this additional code I have updated my example.

Now you can click on your excel sheet where you want to insert and then click the send button on the GUI...

 

#include <GUIConstantsEx.au3>
#include <Excel.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    Local $idSend = GUICtrlCreateButton("Send", 200, 200, 85, 25)
    Global $Radio1 = GUICtrlCreateRadio("22", 56, 136, 49, 17)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop
            Case $idSend ;---------------------------------Send Button Calls Case $iDSend----------Case calls Function named ""SendToExcel()"" below
                SendToExcel()

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example



Func SendToExcel()

    $radioVar = GUICtrlRead($Radio1)
    Local $sWorkbook = @ScriptDir & "\_Excel1.xls"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
     Local $oRange = $oWorkbook.Application.Activecell.Address
     Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $radioVar, $oAddress)

    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)


EndFunc   ;==>SendToExcel

 

 

 

Edited by l3ill
additional info
  • Like 1

Share this post


Link to post
Share on other sites
Hlaurent

Quick example of how to get the active cell using dot notation. Don't know if it's a very elegant solution, but it gives you an idea of what to search for etc.

Very Cool MikahS !

So using this additional code I have updated my example.

Now you can click on your excel sheet where you want to insert and then click the send button on the GUI...

 thank you both  MikahS and  I3ill very much.  i couldn't finish it today though, i feel that i m almost there with your help. 

I3ill 

your example send always "1" to the cell. but it s cool. now i know $oWorkbook.Application.Activecell.Address thing which is pretty good clue for me.  

my all au3s in my workplace. and i forgot to copy them for home. till monday,,, have a nice weekend to you.

thx again. 

Share this post


Link to post
Share on other sites
MikahS

@Hlaurent My pleasure. Let us know how it goes. 


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
Hlaurent

done. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Excel.au3>
#Region ### START Koda GUI section ### Form=C:\Users\hloo\Documents\koda_1.7.3.0\Forms\staj_go.kxf

Example()

Func Example()
Global $Form1 = GUICreate("Form1", 398, 287, 445, 275)
Global $Edit1 = GUICtrlCreateEdit("", 48, 24, 329, 73)
GUICtrlSetData(-1, "Edit1")
Global $Button1 = GUICtrlCreateButton("YAZ", 96, 216, 105, 33)
Global $Button2 = GUICtrlCreateButton("NEXT", 224, 216, 57, 33)
Global $Button3 = GUICtrlCreateButton("BILGI", 8, 24, 33, 225)
Global $Group1 = GUICtrlCreateGroup("BELGE", 48, 112, 57, 81)
Global $Radio1 = GUICtrlCreateRadio("22", 56, 136, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Radio2 = GUICtrlCreateRadio("43", 56, 160, 49, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group2 = GUICtrlCreateGroup("SÜRE", 112, 112, 65, 81)
Global $Radio3 = GUICtrlCreateRadio("30", 128, 136, 33, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Radio4 = GUICtrlCreateRadio("60", 128, 160, 41, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group3 = GUICtrlCreateGroup("BASLAMA", 184, 112, 105, 81)
Global $Radio5 = GUICtrlCreateRadio("15.06.2015", 200, 136, 81, 17)
Global $Radio6 = GUICtrlCreateRadio("29.06.2015", 200, 160, 81, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group4 = GUICtrlCreateGroup("CUMARTESI", 296, 112, 81, 81)
Global $Radio7 = GUICtrlCreateRadio("VAR", 312, 136, 49, 17)
Global $Radio8 = GUICtrlCreateRadio("YOK", 312, 160, 49, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            Case $Button3
   WinActivate("Microsoft Excel") ; go to Excel
                WinWaitActive("Microsoft Excel")
                Sleep(300)
                Send("+{RIGHT 2}")
                Sleep(300)
                Send("^c")
                Send("{RIGHT}")
                Send("{RIGHT}")
                Send("{RIGHT}")
                Send("!{TAB}") ; back
                Sleep(300)
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("^a")
                Send("^v")

          Case $Button1 ;------Send Button Calls Case $iDSend------Case calls Function named ""SendToExcel()"" below
             SendToExcel()
          Case $Button2
             WinActivate("Microsoft Excel") ; -------------------if it s wrong next
                WinWaitActive("Microsoft Excel")
                Sleep(300)
                Send("^h"); triggers excel macro to paint the cell red
                Send("{DOWN}")
                Send("{LEFT}")
                Send("{LEFT}")
                Send("{LEFT}")
                Sleep(300)
                Send("+{RIGHT 2}")
                Sleep(300)
                Send("^c")
                Send("{RIGHT}")
                Send("{RIGHT}")
                Send("{RIGHT}")
                Send("!{TAB}") ; back
                Sleep(300)
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("{TAB}")
                Send("^a")
                Send("^v") ; back
             EndSwitch
WEnd

 EndFunc



   Func SendToExcel()
    if GUICtrlRead($Radio1) = "1" Then ; ------------------------------------------------first part
Local $setradio1 = "22"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio1, $oRange)

ElseIf GUICtrlRead($Radio2) = "1" Then
    Local $setradio2 = "43"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio2, $oRange)
 EndIf
 WinActivate("Microsoft Excel") ; go to Excel
                WinWaitActive("Microsoft Excel")
                Sleep(300)
                Send("{RIGHT}")
                if GUICtrlRead($Radio3) = "1" Then ;----------------------------------------second part
Local $setradio3 = "30"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio3, $oRange)

ElseIf GUICtrlRead($Radio4) = "1" Then
    Local $setradio4 = "60"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio4, $oRange)
 EndIf
 WinActivate("Microsoft Excel") ; go to Excel
                WinWaitActive("Microsoft Excel")
                Sleep(300)
                Send("{RIGHT}")
                Send("{RIGHT}")
                Send("{RIGHT}");-----------------------------------------------------3th part
                if GUICtrlRead($Radio5) = "1" Then
                Local $setradio5 = "15.06.2015"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio5, $oRange)

ElseIf GUICtrlRead($Radio6) = "1" Then
    Local $setradio6 = "29.06.2015"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio6, $oRange)
 EndIf

 WinActivate("Microsoft Excel") ; go to Excel
                WinWaitActive("Microsoft Excel")
                Sleep(300)
                Send("{LEFT}");-----------------------------------------------------4th part
                if GUICtrlRead($Radio7) = "1" Then
                Local $setradio7 = "VAR"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio7, $oRange)

ElseIf GUICtrlRead($Radio8) = "1" Then
    Local $setradio8 = "YOK"
    Local $sWorkbook = "C:\Users\hloo\Desktop\stajlar 2015 taslak\New folder\48.xlsx"
    Local $oWorkbook = _Excel_BookAttach($sWorkbook)
    Local $oRange = $oWorkbook.Application.Activecell.Address
    Local $oAddress = StringReplace($oRange, "$", "")
    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $setradio8, $oRange)
 EndIf
 WinActivate("Microsoft Excel") ;
                WinWaitActive("Microsoft Excel")
                Sleep(300)
                Send("{DOWN}")
                Send("{LEFT 6}")
                Sleep(100)
                Send("!{TAB}")
EndFunc

 

even if this s very very bad coding -i know i admit- now it's functioning very well for me. 

thx again, your contribution helped me a lot. 

Share this post


Link to post
Share on other sites
MikahS

No problem, glad you found a solution. ^_^


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I need to open excel files that may or may not need a password and finally move the files that needs password to manual queue.
      Is there a fastest way to do this?
       
      PS: I have a huge respect for the rules of this forum. I am not asking assistance to override any security measure. I just need to segregate the files that needs passwords.
    • MrCheese
      By MrCheese
      Hi guys,
      without including everything (unless you want it)
      I am copying data from a table in chrome and wanting to paste it into excel.
      Copying in Chrome works.
      I can paste it into the field i want by emulating goto -> ctrl V:
      WinActivate($dataload) WinWaitActive($dataload) Sleep(500) $oWorkbook1.Sheets("ItemReturn").Activate Sleep(500) $msg = "Measuring Sheet" conwrite() ttips2() Local Const $xlUp = -4162 With $oWorkbook1.ActiveSheet ; process active sheet $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) ; get a Range that contains the last used cells $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, "B")).Rows.Count ; get the the row count for the range starting in row/column 1 and ending at the last used row/column $iLastCell = .Cells($iRowCount + 1, "B").End($xlUp).Row ; start in the row following the last used row and move up to the first used cell in column "B" and grab this row number EndWith $NewStartCell = $iLastCell + 2 $msg = "moving to location" conwrite() ttips2() Sleep(250) Send("^g") WinWait("Go To") Sleep(100) Send("B" & $NewStartCell) Sleep(100) Send("{ENTER}") Sleep(500) Send("^v")  
      But, I want to use _excel_rangecopypaste, pasting from the clipboard
      _Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, default, "B" & $NewStartCell,default,$xlPasteValuesAndNumberFormats) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Error pasting cells." & @CRLF & "@error = " & @error & ", @extended = " & @extended) however, this gives me error 4 , extended@:  -2147352567
      How can i fix this or find out how to debug this error?
       
      Thanks
    • Simpel
      By Simpel
      Hi.
      I try to figure out who is using a excel workbook which I can only open "read only". I use this code:
      #include <Array.au3> #include <Excel.au3> Local $sFile = ; excel file with path on a network drive Local $oExcel = _Excel_Open(True, True) Local $oTabelle = _Excel_BookOpen($oExcel, $sFile) Local $aUsers If IsObj($oTabelle) Then $aUsers = $oTabelle.UserStatus _ArrayDisplay($aUsers) EndIf If I am the one allowed to write to the excel file (I'm the first one who opened it) then I will get an array with myself:

      If my collegue opened the excel file first and I run the code I get the following error message:
      "H:\_Conrad lokal\Downloads\AutoIt3\_COX\Tests\test.au3" (9) : ==> The requested action with this object has failed.: $aUsers = $oTabelle.UserStatus $aUsers = $oTabelle^ ERROR The excel file is on a network drive. Is that's the problem?
      Regards, Conrad
    • robertocm
      By robertocm
      change linked image paths in excel 2007 Open XML Files with AutoIt and 7-zip:
      #include <File.au3> ;Change this Local $sFind = "C:\Users\MyUserName\Documents\MyImageFolder\My%20Image1.png" Local $sReplace = "C:\Users\ANOTHERUSERNAME\Documents\AnotherImageFolder\My%20Image1.png" Local Const $sMessage = "Directory to change excel image paths" Local $sFileSelectFolder = FileSelectFolder($sMessage, "") Local $sTempDir = @ScriptDir & "\testdir" ;Required 7-zip Local $PathZipProgram = @ProgramFilesDir & "\7-Zip\" If Not(FileExists($PathZipProgram & "\7z.exe")) Then MsgBox(16, "", "7z.exe not found in path " & $PathZipProgram) Exit EndIf ;look for excel files in selected directory and all subdirectories Local $SFileList = _FileListToArrayRec($sFileSelectFolder, "*.xls.;*.xlsm", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If Not @error Then For $i = 1 To $SFileList[0] DirRemove($sTempDir, 1) ;use x command to keep the folder stucture, -aoa Overwrite All existing files without prompt, use -r to unzip the subfolders from the zip file RunWait('"' & $PathZipProgram & '7z.exe" x -aoa -r "' & $SFileList[$i] & '" -o"' & $sTempDir & '" -y', $PathZipProgram, @SW_HIDE) __ReplaceImagePaths($sTempDir, $sFind, $sReplace) RunWait('"' & $PathZipProgram & '7z.exe" a -r "' & $SFileList[$i] & '" "' & $sTempDir & '\*" -tzip -y', $PathZipProgram, @SW_HIDE) Next Else MsgBox(16, "Error", "No files were found in the folder specified.") EndIf DirRemove($sTempDir, 1) Func __ReplaceImagePaths($sTempDir, $sFind, $sReplace) ;List all files with .xml.rels extension in the directory \xl\drawings\_rels Local $aFileList = _FileListToArray($sTempDir & "\xl\drawings\_rels", "*.xml.rels", 1, True) If @error = 1 Then ;MsgBox (0, "", "Path was invalid") SplashTextOn("Title", "Path was invalid", -1, -1, -1, -1, 1, "", 24) Sleep(2000) SplashOff() Exit EndIf If @error = 4 Then ;MsgBox (0, "No files", "No files were found") SplashTextOn("Title", "No files were found", -1, -1, -1, -1, 1, "", 24) Sleep(2000) SplashOff() Exit EndIf Local $iRetval ;Loop through the array For $i = 1 To $aFileList[0] $iRetval = _ReplaceStringInFile($aFileList[$i], $sFind, $sReplace) Next EndFunc  
      Some references:
      https://stackoverflow.com/questions/37145369/change-path-to-picture-links-in-excel http://www.jkp-ads.com/Articles/Excel2007FileFormat.asp EDITED:
      Note: it seems that if User Account Control (UAC) is enabled then 7zip is unable to overwrite the destination file (using the same name).
      In this case, a possible solution would be to rename the original excel file before (see _PathSplit in help file).
      In my case i prefer just to disable UAC
    • SOF-TECH
      By SOF-TECH
      Dear all,
      Can someone show  me how to en hance the below function to write in CSV  into column  and rows the input values ? 
      I am getting this result: 

      I would like the result to be as this 

      From A1:C1 is for headers
      From A2:C2 is for input Data
      Global Const $GUI_EVENT_CLOSE = -3 $sDataFilePath = @ScriptDir & "\Records.csv" #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Demo1: New Record", 580, 115) $Input1 = GUICtrlCreateInput("", 10, 30, 270, 21) $Input2 = GUICtrlCreateInput("", 300, 30, 270, 21) $Input3 = GUICtrlCreateInput("", 10, 80, 270, 21) $Label1 = GUICtrlCreateLabel("Name:", 10, 10, 35, 17) $Label2 = GUICtrlCreateLabel("ID:", 300, 10, 18, 17) $Label3 = GUICtrlCreateLabel("Phone No:", 10, 60, 55, 17) $Button1 = GUICtrlCreateButton("Save to CSV", 450, 70, 120, 30) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _ExportData() MsgBox(64, @ScriptName, "Record Saved.") EndSwitch WEnd Func _ExportData() If Not FileExists($sDataFilePath) Then FileWriteLine($sDataFilePath, "Name;ID;Phone No.;") EndIf For $i = $Input1 To $Input3 FileWrite($sDataFilePath, GUICtrlRead($i) & ";") Next FileWriteLine($sDataFilePath, "") EndFunc ;==>_ExportData May be Excel UDF has be to be added but I can manage that my self  
      Thank you in advance
×