Public variable for captura path in vba excel

0 votes

I need to record the path of the excel file in a public VBA excel variable. I have a macro that utilises the path several times across various modules. My issue arises when the variable is declared in the Option Explicit Contex.

`Option Explicit Public ruta As String

ruta = ActiveWorkbook.Path

Public Const varRuta = ruta & "\ValidacionesSunat"

Sub EdufarmaEstadoRevisado()

the variables you must use in the code TextFile Should Be A Number I, J, K, L, and M, As Integer String: MyFile Dim Dark Zone Low values The same dim batch Set batchDe10 to Set batchSaldoUnits to 

On Error Resume Next Kill varRuta & "." On Error GoTo 0 `

Jan 22 in Others by Kithuzzz
• 27,740 points
34 views

1 answer to this question.

0 votes

An assignment statement (as ruta = ActiveWorkbook) cannot be used. Outside of a Sub() or Function is the Path ()

Therefore, take into account the following adjustments to your ruta-related variables along with a few more recommendations/advice.

Option Explicit

Public varRuta As String

Public Const varRutaLastBit = "\ValidacionesSunat"

Sub EdufarmaEstadoRevisado()

    varRuta = ActiveWorkbook.Path & varRutaLastBit
    
    'variables that you need to use in the code
    Dim TextFile As Integer
    Dim iCol As Long '<-- use Long instead of Integer
    Dim myRange As Range
    Dim cVal As Range
    Dim i As Long, _
        j As Long, _
        k As Long, _
        l As Long, _
        m As Long
    Dim myFile As String
    Dim zona
    Dim valores As Long
    Dim batch '<-- implicitly assumed As Variant
    Dim batchDe10 '<-- implicitly assumed As Variant
    Dim batchSaldoUnidades
    
    On Error Resume Next
    Kill varRuta & "."
    On Error GoTo 0

End Sub

Please be aware that any missing type declarations right after a variable may cause the VBA interpreter to treat the variable as being of type "Variant" with regard to any comments or suggestions regarding Dim.

answered Jan 22 by narikkadan
• 51,240 points

Related Questions In Others

0 votes
1 answer

Language independent way to get "My Documents" folder in VBA Excel 2003

 Hello :)  This code may help you in your ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,640 points
146 views
0 votes
1 answer

Why is just an ID in the URL path a bad idea for SEO?

yes it affects the click through rates ...READ MORE

answered Feb 20, 2022 in Others by narikkadan
• 51,240 points
115 views
0 votes
1 answer
0 votes
1 answer

Can a worksheet ActiveX ComboBox work on a Mac?

ActiveX is an outdated Windows technology that ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 51,240 points
66 views
0 votes
0 answers

Strikethrough in Excel VBA

When I enter the second date in ...READ MORE

Nov 27, 2022 in Others by Kithuzzz
• 27,740 points
68 views
0 votes
1 answer

Excel VBA- Creation of a New datablock with criteria

To insert the dropdown, you can go ...READ MORE

answered Jan 12 in Others by narikkadan
• 51,240 points
33 views
0 votes
1 answer

I want to compare two Excel files and highlight the differences with VBA

The workbook doesn't have the UsedRange property ...READ MORE

answered Jan 13 in Others by narikkadan
• 51,240 points
43 views
+1 vote
1 answer

How to use VBA in Excel for Google Search?

Try this: Private Const LicenseRegistration As String = ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 51,240 points
316 views
0 votes
1 answer

How to get the excel file name / path in VBA

Use FullName, for example: strFileFullName = ThisWorkbook.FullName ...READ MORE

answered Dec 23, 2022 in Others by narikkadan
• 51,240 points
60 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP