Last active
July 24, 2024 20:12
-
-
Save simply-coded/758e2557ccd1a55b46765d8bb1099ec6 to your computer and use it in GitHub Desktop.
Use VBScript to create, open, and edit excel files. ( Excel needs to be installed on your computer ).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Microsoft Excel Automation Basics | |
':: Create and edit an Excel File. | |
'--------------------------------- | |
'create the excel object | |
Set objExcel = CreateObject("Excel.Application") | |
'view the excel program and file, set to false to hide the whole process | |
objExcel.Visible = True | |
'add a new workbook | |
Set objWorkbook = objExcel.Workbooks.Add | |
'set a cell value at row 3 column 5 | |
objExcel.Cells(3,5).Value = "new value" | |
'change a cell value | |
objExcel.Cells(3,5).Value = "something different" | |
'delete a cell value | |
objExcel.Cells(3,5).Value = "" | |
'get a cell value and set it to a variable | |
r3c5 = objExcel.Cells(3,5).Value | |
'save the new excel file (make sure to change the location) 'xls for 2003 or earlier | |
objWorkbook.SaveAs "C:\Users\UserName\Desktop\vbsTest.xlsx" | |
'close the workbook | |
objWorkbook.Close | |
'exit the excel program | |
objExcel.Quit | |
'release objects | |
Set objExcel = Nothing | |
Set objWorkbook = Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Microsoft Excel Automation Basics | |
':: Open and edit an Excel File. | |
'--------------------------------- | |
'create the excel object | |
Set objExcel = CreateObject("Excel.Application") | |
'view the excel program and file, set to false to hide the whole process | |
objExcel.Visible = True | |
'open an excel file (make sure to change the location) .xls for 2003 or earlier | |
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\UserName\Desktop\vbsTest.xlsx") | |
'set a cell value at row 3 column 5 | |
objExcel.Cells(3,5).Value = "new value" | |
'change a cell value | |
objExcel.Cells(3,5).Value = "something different" | |
'delete a cell value | |
objExcel.Cells(3,5).Value = "" | |
'get a cell value and set it to a variable | |
r3c5 = objExcel.Cells(3,5).Value | |
'save the existing excel file. use SaveAs to save it as something else | |
objWorkbook.Save | |
'close the workbook | |
objWorkbook.Close | |
'exit the excel program | |
objExcel.Quit | |
'release objects | |
Set objExcel = Nothing | |
Set objWorkbook = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need help with something urgent, can anyone help please? I have a excel file with data like
Q1. A. B. C. D.
Q2 A. B. C. D
Q3. A1 B1. C1. D2
I want to be able to create answer key like
Q1. A
Q1. B
Q1. C
Q1. D
Q2. A
Q2. B
Q2. C
Q2. D
and so on..Q1 has 4 choices so I need Q1 against each of the choice when transpose. Any help really appreciated