Sign in to follow this  
Followers 0
lorenkinzel

Excel copy range, paste to active sheet

1 post in this topic

This is stripped-down from a 'helper' GUI that I use with my estimating spreadsheet.

#include <GUIConstantsEx.au3>
#include <Excel.au3>
$oExcel = ObjGet("", "Excel.Application")
If @error Then
MsgBox(0, "", "You need to have Excel running for this to work", 4)
Exit
EndIf
GUICreate("x", 80, @DesktopHeight * .925, @DesktopWidth * .75, 10)
WinSetOnTop("x", "", 1)
$label3 = GUICtrlCreateLabel("", 4, @DesktopHeight * .875 - 70, 72, 25)
$copy = GUICtrlCreateButton("copy", 10, (@DesktopHeight * .165 + 10), 60, 25)
GUICtrlSetState($copy, $GUI_SHOW)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Select
  Case $nMsg = $GUI_EVENT_CLOSE
   Exit
  Case $nMsg = $copy
   $sheetname = _ExcelSheetNameGet($oExcel)
   GUICtrlSetData($label3, $sheetname)
   $goback = GUICtrlRead($label3)
   With $oExcel
    .ActiveSheet.Unprotect;sheet protection in place to save me from boo-boos during data entry
    .Sheets("Sheet3").Visible = True;unhide sheet that I wish to copy from
    Sleep(50)
    .Sheets("Sheet3").Select;open the sheet
    .Range("A3:P11").Select
    .Selection.Copy
    _ExcelSheetActivate($oExcel, $goback);back to sheet in use
    Sleep(50)
    .ActiveSheet.Paste;uses currently active cell (on $goback) as upper left
    .Sheets("Sheet3" ).Visible = False;re-hide the sheet
    .ActiveSheet.Protect;re-protect the active sheet
    ;.DrawingObjects = False;>>>>>>>>>>misc. conditions of sheet protection
    ;.Contents = True
    ;.Scenarios = True
    ;.AllowFormattingColumns = True
    ;.AllowInsertingRows = True
   EndWith
EndSelect
WEnd

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  
Followers 0