VBA Macro to select/open a file

ummjay

Board Regular
Joined
Oct 1, 2010
Messages
193
Hi! I am trying to create a vba macro to select a file, then open, and use that file to add in an empty column (between B and C).

I am able to get it, so I can select the file, but not getting it to work to use that file and open it.

Any ideas what I'm doing wrong?

VBA Code:
Sub CopyWorkbook()

Dim NewFN As Workbook
Dim curWorkbook As Workbook
'
'-----------------------------------------------------------'
'   Request New Excel File
'
    NewFFN = Application.GetOpenFilename(Title:="Please Select File")
    If NewFFN = False Then
        MsgBox "Macro Terminated Due to No File Selected"
        Exit Sub
        Else
            Workbooks.Open Filename:=NewFFN
    End If
    'Set NewFN = ActiveWorkbook
'
'-----------------------------------------------------------

Application.Calculation = xlCalculationAutomatic
                 
                              
Workbooks.Open NewFFN
'With Workbooks.Open(NewFN)
'CloseThisWorkbook
MsgBox "No valid file name was supplied.", _
vbCritical, "Can't rename"


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
This is the minimum you need to open your file. From here you can go on with your project.
VBA Code:
Option Explicit
Sub CopyWorkbook()
    Dim NewFFN  As Variant
    NewFFN = Application.GetOpenFilename(Title:="Please Select File")
    If NewFFN = False Then
        MsgBox "Macro Terminated Due to No File Selected"
        Exit Sub
    Else
        Workbooks.Open Filename:=NewFFN
    End If
    Application.Calculation = xlCalculationAutomatic   '<- may not be necessary
End Sub
 
Upvote 0
Solution
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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