VBA, open concern folder directly and message display off

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
I am using following code;

Code:
Sub t()

Dim sh As Worksheet, fPath As String, fName As String
Set sh = ActiveSheet
fPath = "ThisWorkbook.Path\Backup\"
fName = Application.GetOpenFilename("Excel Files (" & fPath & "*.xlsb)," & fPath & "*.xlsb")
Set wb = Workbooks.Open(fName)
wb.Sheets("Layout").Select
 Columns("BM:BO").Select
    Selection.EntireColumn.Hidden = False
    Range("BN5").Select
    ActiveSheet.Range("$A$5:$DZ$500").AutoFilter Field:=66
    Selection.EntireColumn.Hidden = True
    Range("BM5").Select
Range("B6:Q498").Copy sh.Range("B6")
wb.Close False




End Sub

#1 It is giving error message which we need press yes
A formula or sheet you want to move or copy contains the name 'Stitch', which already exist on the destination worksheet. Do you want to use this version of the name?
. To use the name as defined in the destination sheet, click Yes
. To rename the range referred to in formula or worksheet, click No, and enter a new name in Name Conflict dialog box.

I want this error not to display.

#2 Second thing, I want to open always the folder "Thisworkbook.path/Backup"
Currently it is opening another folder, then I need to select destination again and again
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Re: Help in VB Code, open concern folder directly and message display off

Code:
Range("B6:Q498").Copy sh.Range("B6")
Don't know if you realize it, but this does not copy just the filtered rows. It copies hidden rows as well. To copy only the filtered rows it should be:
Code:
Range("B6:Q498").SpecialCells(xlCellTypeVisible).Copy sh.Range("B6")
To stop the message from appearing, you can put this statement before the line that causes it
Code:
Application.DisplayAlerts = False
And this statement immediately after the line that causes the message
Code:
Application.DisplayAlerts = True
 
Upvote 0
Re: Help in VB Code, open concern folder directly and message display off

Do you mean like this?
Code:
Sub t()

Dim sh As Worksheet, fPath As String, fName As String
Set sh = ActiveSheet
fPath = "ThisWorkbook.Path\Backup\"
fName = Application.GetOpenFilename("Excel Files (" & fPath & "*.xlsb)," & fPath & "*.xlsb")
Set wb = Workbooks.Open(fName)
wb.Sheets("Layout").Select
 Columns("BM:BO").Select
    Selection.EntireColumn.Hidden = False
    Range("BN5").Select
    ActiveSheet.Range("$A$5:$DZ$500").AutoFilter Field:=66
    Selection.EntireColumn.Hidden = True
    Range("BM5").Select
Range("B6:Q498").Copy
Application.DisplayAlerts = False
sh.Range ("B6")
Application.DisplayAlerts = True
wb.Close False




End Sub
 
Upvote 0
Re: Help in VB Code, open concern folder directly and message display off

More like this

Code:
Sub t()
Dim sh As Worksheet, fPath As String, fName As String
Set sh = ActiveSheet
fPath = "ThisWorkbook.Path\Backup\"
fName = Application.GetOpenFilename("Excel Files (" & fPath & "*.xlsb)," & fPath & "*.xlsb")
Set wb = Workbooks.Open(fPath & fName)
wb.Sheets("Layout").Select
Application.DisplayAlerts = False
 Columns("BM:BO").Select
    Selection.EntireColumn.Hidden = False
    Range("BN5").Select
    ActiveSheet.Range("$A$5:$DZ$500").AutoFilter Field:=66
    Selection.EntireColumn.Hidden = True
    Range("BM5").Select
Range("B6:Q498").SpecialCells(xlCellTypeVisible).Copy sh.Range("B6")
Application.DisplayAlerts = True
wb.Close False
End Sub
 
Last edited:
Upvote 0
Re: Help in VB Code, open concern folder directly and message display off

I think this is probably what you are looking for.

To get it to open the dialogue box in another directory besides the default directory you have to use ChDir method.
Code:
Sub t()
Dim sh As Worksheet, fPath As String, fName As String
Set sh = ActiveSheet
ChDir ThisWorkbook.Path & "\Backup"
fName = Application.GetOpenFilename("Excel Files (*.xlsb), *.xlsb")
Set wb = Workbooks.Open(fName)
wb.Sheets("Layout").Select
Application.DisplayAlerts = False
 Columns("BM:BO").Select
    Selection.EntireColumn.Hidden = False
    Range("BN5").Select
    ActiveSheet.Range("$A$5:$DZ$500").AutoFilter Field:=66
    Selection.EntireColumn.Hidden = True
    Range("BM5").Select
Range("B6:Q498").SpecialCells(xlCellTypeVisible).Copy sh.Range("B6")
Application.DisplayAlerts = True
wb.Close False
End Sub
 
Upvote 0
Re: Help in VB Code, open concern folder directly and message display off

Sorry sir, this is giving error
Any solution to open relative folder directly with the code;
thiworkbook.path/backup
 
Last edited:
Upvote 0
Re: Help in VB Code, open concern folder directly and message display off

Sorry sir, this is giving error
Any solution to open relative folder directly with the code;
thiworkbook.path/backup

I am out of ideas, sorry.
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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