Code:
;########################## Start ###############################################
#SingleInstance force
version = Revit MEP
Excelversion = Microsoft Excel
Msgbox, This program copies cell values from Excel to Revit.`n`nOpen the key schedule view in Revit, and select the top left most cell.`nYou should have created the necessary rows already in Revit.`n`nOpen the excel file and select the top left most cell to start copying from.`nYou should know the number of rows and columns that are to be copied.`n`n Press OK only after doing these, else this program will fail.`n`n (Modified by David Rushforth from an original program by Nicholas Iyadurai)
SetTitleMatchMode 1
IfWinnotExist %version%
{
MsgBox,,, %version% is not open. `n The program will now exit., 2
ExitApp
}
IfWinnotExist %Excelversion%
{
MsgBox,,, %Excelversion% is not open. `n The program will now exit., 2
ExitApp
}
GetFileInfo:
Gui, Add, Text,, No of Rows to be copied:
Gui, Add, Text,, No of Columns to be copied:
Gui, Add, Edit, vNiRowNo ym ; The ym option starts a new column of controls.
Gui, Add, Edit, vNiColNo
Gui, Add, Button, default, OK ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Show,, Copy Excel to Revit
return ; End of auto-execute section. The script is idle until the user does something.
GuiClose:
ButtonOK:
Gui, Submit ; Save the input from the user to each control's associated variable.
if NiRowNo =
{
MsgBox,,, You entered 0 rows. `n The program will now exit, 2
ExitApp
}
if NiColNo =
{
MsgBox,,, You entered 0 columns. `n The program will now exit, 2
ExitApp
}
NiColNominus := NiColNo - 1
NiRowNominus := NiRowNo - 1
copyexcel:
loop, %NiRowNo%
{
currentcolumn := 1
loop, %NiColNo%
{
if currentcolumn <> 1
{
WinActivate %version%
Send {Tab}
}
currentcolumn := currentcolumn + 1
WinActivate %Excelversion%
Send {Control down}c{Control up}{Tab}
WinActivate %version%
Send {space}{Backspace}{Control down}v{Control up}
}
Send {Enter}{Left %NiColNominus%}
WinActivate %Excelversion%
Send {Down}{Left %NiColNo%}
}
;########################## End ###############################################
MsgBox, 0, Done., The cells have been copied. `n Please check the data.
ExitApp
;##############################################################################