Jump to content
Sign in to follow this  

Excel copy range, paste to active sheet

Recommended Posts


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)
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)
While 1
$nMsg = GUIGetMsg()
  Case $nMsg = $GUI_EVENT_CLOSE
  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
    .Sheets("Sheet3").Select;open the sheet
    _ExcelSheetActivate($oExcel, $goback);back to sheet in use
    .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

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.