I created an excel file that runs a macro as soon as it starts, when I open the file normally the macro is successfully executed but when I open my ".vbs" file an error occurs, can someone help me?
Error:
VBS Code:
VBA Code:
Dim myMostRecentFile As String, ola As String
Dim Ws As Integer
Private Sub WriteValues()
Ws = ActiveWorkbook.Sheets.Count
For counter = 1 To Ws
Worksheets(counter).Select
ActiveCell = Range("AC12").Select
If ActiveCell.Value = "" Then
ActiveCell.Select
With Selection
.Name = "Date"
.HorizontalAlignment = xlRight
End With
Range("AD12").Select
With Selection
.Name = "Time"
.HorizontalAlignment = xlRight
End With
Range("AE12").Select
With Selection
.Name = "Value"
End With
Else
End If
Range("AC13").Select
If ActiveCell.Value = "" Then
Call FillCells
Else
End If
Next
End Sub
Sub FillCells()
ActiveCell.Value = Range("U13").Value
Range("AE13").Value = WorksheetFunction.Sum(Range("W13:W108"))
Range("AF13").Value = "kWh"
End Sub
Private Sub recentFilesSpecificFolder()
Dim myFile As String, myRecentFile As String, myDirectory As String, fileExtension As String
Dim recentDate As Date
myDirectory = Environ("userprofile") & "\Documents\Projeto_Luis\Andre\EEC\QEIM\QEIM_geral"
fileExtension = "*.xls"
If Right(myDirectory, 1) <> "\" Then myDirectory = myDirectory & "\"
myFile = Dir(myDirectory & fileExtension)
If myFile <> "" Then
myRecentFile = myFile
recentDate = FileDateTime(myDirectory & myFile)
Do While myFile <> ""
If FileDateTime(myDirectory & myFile) > recentDate Then
myRecentFile = myFile
recentDate = FileDateTime(myDirectory & myFile)
End If
myFile = Dir
Loop
End If
myMostRecentFile = myRecentFile
MsgBox "Path: " & myDirectory & vbCrLf & "File: " & myMostRecentFile
Workbooks.Open Filename:=myDirectory & myMostRecentFile
Call WriteValues
End Sub
Sub AutoRunMacro()
Call recentFilesSpecificFolder
End Sub
Error:
VBS Code: