Variable Filename Help

JBerr

New Member
Joined
Dec 10, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I am new to VBA coding and working on automating a process that I perform every month. I recorded the macro below which works as intended if I am testing using the specific specified filename. I need both the Capital One Allocation & transaction download filenames to be variable. I have searched the boards and was unable to find something similar enough for me to try and use it. This is called from a user form:

VBA Code:
Private Sub Yes_Click()

    Windows("Capital One Allocation - Rev IW.xlsm").Activate
    Windows("2020-11-29_transaction_download.xlsx").Activate
    
'Copy range
    
    Range("A2:G100").Select
    Selection.Copy
    Windows("Capital One Allocation - Rev IW.xlsm").Activate
    Range("B3").Select
    ActiveSheet.Paste
    Range("B2:H53").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("Download").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Download").Sort.SortFields.Add2 Key:=Range( _
        "D3:D53"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("Download").Sort.SortFields.Add2 Key:=Range( _
        "B3:B53"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Download").Sort
        .SetRange Range("B2:H53")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("B3").Select

Unload DownloadImport

End Sub

Any help you can give would be appreciated.
 

JBerr

New Member
Joined
Dec 10, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Update:

using the code you gave me to call the userform:

VBA Code:
  With DownloadImport
    Set .PickedWorkbook = DLWorkbook
    .Show

    End With

Solved the Runtime 91 error. I am still working on incorporating the open file check code you gave me. Thank You very much for all the help you have given so far!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,493
Office Version
  1. 2013
Platform
  1. Windows
You are welcome!
 

Forum statistics

Threads
1,136,288
Messages
5,674,870
Members
419,531
Latest member
Mjsherwin

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
Top