Jump to content
Sign in to follow this  
Hlaurent

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

Recommended Posts

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

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

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

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

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

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

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

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

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

Share this post


Link to post
Share on other sites

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

@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

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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By GOSM
      Hey,
      as part of a larger Programm I am trying to copy the values from one cell in an Excel file to another. The code I am using is the folowing.
       
      Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeCopyPaste($oExcel.ActiveSheet, "V4:W43", "X4", False, $xlPasteValues, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 4", "Error copying rows." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 4", "2 Rows successfully pasted from the clipboard to row 1.") As I understood it the option $xlPasteValues should do the trick  but it is still copying the inserted formulas. I attached a test code and excel file.
      Thanks for the help Simon
      Copy Values Test.zip
    • By Chimp
      An "improper" "unusual" use of Excel
      the script allows the creation of artistic images by simply coloring the background of the individual cells of the Excel workbook.
      Although definitely useless ... I find it quite funny though
      have a good time
      many thanks to @UEZ , @Malkey , @water
      p.s.
      I think the pixelite + color to array process can be simplified, but I used the two ready-made functions provided by UEZ and Malkey. I thank both of you (credits  and links in listing)
      p.p.s.
      strange behaviour: while excell is filling cells, if you move the mouse pointer off the excell window, the fill speed increases ... (?)

       
      ; =============================================================================================================================== ; Name ..........: Excel in art ; Description ...: This script allows the creation of artistic images in Excel from a choosed picture. ; The picture is done by simply coloring the background of the individual cells of an Excel workbook. ; Although definitely useless, I find it quite funny though ; ; Return values .: An artistic image in an Excel workbook ; Author ........: Addiego Gianni (chimp) ; Modified ......: ; Remarks .......: Many thanks to UEZ, Malkey and Water ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== #include <GDIPlus.au3> #include <Excel.au3> _PixelsToCells(50) ; <-- Parameter 50 is the cumber of horizontal Excel cells to be filled MsgBox(64, "All done", "Excel art is ready") Func _PixelsToCells($iHcells = 50) ; Check application object Local $oExcel = _Excel_Open() If Not IsObj($oExcel) Then MsgBox(16, "Error", "Sorry, You need to have 'Excel' intalled") ; Choose Image File Local $sPath = FileOpenDialog("Choose Image File", @ScriptDir & "", "Images (*.gif;*.png;*.jpg;*.bmp)| All (*.*)") If $sPath = '' Then Exit MsgBox(16, "Error", "Sorry, no image was chosen") ; Create a new Excel workbook $oWorkbook = _Excel_BookNew($oExcel, 1) ; initialize GDI+ _GDIPlus_Startup() Local $hBmp = _GDIPlus_BitmapCreateFromFile($sPath) Local $iWidth = _GDIPlus_ImageGetWidth($hBmp) ; get image width ; Local $iHeight = _GDIPlus_ImageGetHeight($hBmp) ; not needed here Local $iStep = $iWidth / $iHcells ; calculate the pixelation factor Local $hBitmap_new = _GDIPlus_PixelateBitmap($hBmp, $iStep) ; pixelate the image Local $aPixelColors = _FileImageToArray($hBitmap_new) ; get pixel colors ; reduce Excel columns width Local $xx = 1, $yy = 1 For $iCol = 0 To UBound($aPixelColors, 2) - 1 Step $iStep $oWorkbook.Sheets(1).Columns($xx).ColumnWidth = 1 $xx += 1 Next ; reduce Excel rows height For $iRow = 0 To UBound($aPixelColors) - 1 Step $iStep $oWorkbook.Sheets(1).Rows($yy).RowHeight = 9 $yy += 1 Next $xx = 1 $yy = 1 For $iRow = 0 To UBound($aPixelColors) - 1 Step $iStep For $iCol = 0 To UBound($aPixelColors, 2) - 1 Step $iStep $oWorkbook.Sheets(1).Range(_Excel_ColumnToLetter($xx) & $yy).Interior.Color = Number("0x" & $aPixelColors[$iRow][$iCol]) $xx += 1 Next $yy += 1 $xx = 1 Next _GDIPlus_BitmapDispose($hBmp) _GDIPlus_Shutdown() EndFunc ;==>_PixelsToCells ; by UEZ ; https://www.autoitscript.com/forum/topic/167707-imagepixelate/?do=findComment&comment=1227509 Func _GDIPlus_PixelateBitmap($hBitmap, $iPixelate, $bSmooth = 1) Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap) Local $iNewW = Round($iWidth / $iPixelate, 0), $iNewH = Round($iHeight / $iPixelate, 0) Local $hBitmap_scaled = _GDIPlus_BitmapCreateFromScan0($iNewW, $iNewH) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_scaled) Local $iInterpolation = 5 If $bSmooth Then $iInterpolation = $GDIP_INTERPOLATIONMODE_BILINEAR _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $iInterpolation) _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBitmap, 0, 0, $iNewW, $iNewH) _GDIPlus_GraphicsDispose($hCtxt) Local $hBitmap_pixelated = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_pixelated) _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $GDIP_INTERPOLATIONMODE_NearestNeighbor) _GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBitmap_scaled, 0, 0, $iNewW, $iNewH, -$iPixelate, -$iPixelate, $iWidth + 2 * $iPixelate, $iHeight + 2 * $iPixelate) _GDIPlus_GraphicsDispose($hCtxt) Return $hBitmap_pixelated EndFunc ;==>_GDIPlus_PixelateBitmap ; by Malkey ; https://www.autoitscript.com/forum/topic/112540-is-there-a-function-for-reading-images-into-2d-arrays/?do=findComment&comment=788472 Func _FileImageToArray($hImage) Local $Reslt, $stride, $format, $Scan0, $iIW, $iIH ; , $hImage Local $v_Buffer, $width, $height ; _GDIPlus_Startup() ; $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iIW = _GDIPlus_ImageGetWidth($hImage) $iIH = _GDIPlus_ImageGetHeight($hImage) ProgressOn("Progress Bar", "Filling a " & $iIW & " x " & $iIH & " size array.", "0 percent") $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iIW, $iIH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Local $aArray[$height][$width] For $j = 0 To $iIH - 1 For $i = 0 To $iIW - 1 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) $aArray[$j][$i] = StringRegExpReplace(Hex(DllStructGetData($v_Buffer, 1), 6), "(.{2})(.{2})(.{2})", "\3\2\1") ; To RGB format Next ProgressSet(Int(100 * $j / ($iIH)), Int(100 * $j / ($iIH)) & " percent") Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) ProgressOff() _GDIPlus_ImageDispose($hImage) Return $aArray EndFunc ;==>_FileImageToArray  
    • By Zaoka
      Hi guys
      Need little help with filtering.
      I'm trying to filter specific weeks from power pivot table using this code recorded with Excel VBA :
       
      #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\....\Orders.xlsb") $oWorkbook.PivotTables("PivotTable1").PivotFields( _ "[Report 2].[Week].[Week]").VisibleItemsList = Array( _ "[Report 2].[Week].&[10]", "[Report 2].[Week].&[11]", _ "[Report 2].[Week].&[12]", "[Report 2].[Week].&[13]", _ "[Report 2].[Week].&[14]", "[Report 2].[Week].&[15]") But get error
      error: Array(): undefined function. Not sure how to resolve this.
    • By Rajat231
      I am trying this code to create multiple workbooks eachone  shall be copy of one worksheet from a workbook having multiple sheets ( keeing the name same)
      SavingWorksheets.au3
    • By Zaoka
      Hi guys,
      i have simple report in PowerPivot that shows Orders (Values) by Regions (Row) and Weeks (Columns). In Filter field is WeekDAYS (Monday,Tuesday,Wednesday,Thursday etc )
      how to filter WeekDAYS Filed on WEEKDAYYesterday with autoit ?
      my junky try
      #include <Date.au3> #include <Excel.au3> Local $sWEEKDAYYesterday = _DateDayOfWeek(@WDAY-1) Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\.......\Orders.xlsb") Sleep (5000) $oExcel.ActiveWorkbook.RefreshAll Sleep (5000) $oExcel.Application.Sheets("Sheet1").PivotTables("PivotTable1").PivotFields("WeekDAYS").PivotFilters($sWEEKDAYYesterday)  
      Error result
      $oExcel.Application.Sheets("PivotTable1").PivotTables("PivotTable1").PivotFields("WeekDAYS").PivotFilters($sWEEKDAYYesterday) $oExcel.Application^ ERROR  
×
×
  • Create New...