0
votes

Not a vbscript expert and I'm beginning to wonder if I remember any of it.

I simply want to obtain today's date without generating, "Microsoft VBScript runtime error: Object required: 'aqDateTime' at line (21,1)". I know it will be obvious to someone here and should probably be obvious to me too.

I am working with an Excel spreadsheet that will need to have cells updated with another date based off of whatever today's date happens to be. Obtaining today's date is the problem for me.

Below is the relevant code. The line near the end of the snippet, "CurrentDate = aqDateTime.Today" is where the error occurs.

I'm not just looking for help on the code though. I would appreciate learning the reasons behind it too. What am I overlooking? Thanks!

dim CurrentDate
dim objExcel, objWorkbook, objWorksheet, strCellValue

'Launch Excel
Set objExcel = CreateObject("Excel.Application")

'Make the spreadsheet visible
objExcel.Application.Visible = True

'Open the workbook
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\QA_Admin\Report\transactiontemplate.xls")

'Select a worksheet
Set objWorksheet = objWorkbook.Worksheets(1)

'Obtain the current date
CurrentDate = aqDateTime.Today

DayOfWeek = aqDateTime.GetDayOfWeek(CurrentDate)

.....
1
You have nothing declared as aqDateTime in your code, so you can't read its Today property. Where do you magically expect aqDateTime to appear from? You can't access an object that you haven't declared and assigned a value to first.Ken White

1 Answers

1
votes

To get the current date use the method Date and to get the day of week use the method weekday as shown below:

'Obtain the current date 
CurrentDate = Date 
DayOfWeek = Weekday(CurrentDate)     ' By default, the weekday returns 1 for a sunday, 2 for monday...7 for saturday.

If you want to get the name of the day, you can use the method WeekDayName as shown below:

Dim strDayName
strDayName = WeekDayName(weekDay(date))      'Returns today's Name(like Friday)