VBS Script error

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
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?


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:

Capturar.JPG




VBS Code:

error.JPG
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You can't run a macro without first opening the file that contains the macro - either by explicitly opening it, or by including the full path and file name in the Run parameter.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top