Consulting

Results 1 to 7 of 7

Thread: Solved: Macro Equation

  1. #1

    Solved: Macro Equation

    I don't know if this is the correct term, but I hope you guys understand. Please bear with me as I'm a newbie when it comes to this.

    I am having a hard time to reflect one equation to another equation. I am not sure but this might need dimming. Requesting for backup


    [VBA]Sub test232()
    Dim FName4
    Dim FName

    FSource = "Y:\MNLGSCSALNNP\Administrative\CnC\Tools\"

    FName4 = "All-In-One Updater\KCForwarder Updater*.xls*"
    FName = FName & "4"

    Workbooks.Open (FSource & FName)

    End Sub[/VBA]


    I want FName to reflect the FName4 value.

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    [VBA]FName = FName4[/VBA]
    HTH. Dave

  3. #3
    Hi Dave,

    Thanks for your response. The code above is just an example. Im doing it because im performing a loop. there's a lot of links and i want to shorten the code.

    my loop code is like this:

    [vba]
    FSource = "C:/Tools/"
    FName1 = FileA
    FName2 = FileB
    FName3 = FileC

    x = 1
    Loop1:
    x = 1 + 1
    If x = 5 Then GoTo EndThis


    FName = FName & x

    Workbooks.Open (FSource & FName)

    GoTo Loop1
    [/vba]

    like that
    so i need to call FName to increment the value from FName1 to FName3 for example

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to the forum.

    do you want to open all files in a folder?

    this might help:
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=9
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Regular
    Joined
    Mar 2013
    Posts
    38
    Location
    hi

    to loop you must use "x = x + 1" instead of "x = 1 + 1" . Now you can reach 5.
    "Amat Victoria Curam"

  6. #6
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    This is an example of how you might 'reword' what you've written:

    [VBA]Sub OpenFiles()

    Dim FSource As String
    Dim Fname(1 To 3) As String
    Dim count As Integer


    FSource = "C:/Tools/"
    Fname(1) = FileA
    Fname(2) = FileB
    Fname(3) = FileC

    For count = 1 To 3
    Workbooks.Open (FSource & Fname(count))
    Next count

    End Sub[/VBA]

    If you want to open all excel files in a folder then Mancubus's solution is probably the way to go.

  7. #7
    Hi Sassora,

    your code is exactly what i'm looking for. Man, you are great. For everyone who replied, thank you as well.

    I didn't know that "()" made this possible. Thank you once again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •