Open/Import/Close using a Server Address

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi - I have this code for opening a closed workbook, copying data, then closing the workbook. How do i change the fPath to use "\\Server\Folder\SubFolder\SubSubFolder" instead of using a drive letter?

thanks!

Sub Test_GetValues()
Dim fPath As String, fOpen As Variant, wb As Workbook, rng1 As Range, rng2 As Range
fPath = "K:\Folder\Subfolder\SubSubFolder" & Sheets("SheetXXX").Range("A2")'specify default drive and folder for GetOpenFilename
ChDrive Left(fPath, 1)
ChDir fPath
'get workbook
fOpen = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
If fOpen <> False Then Set wb = Workbooks.Open(fOpen) Else GoTo handling
'get ranges
With Application
Set rng1 = .InputBox("Select range to pull", "Get data", , , , , , 8)
ThisWorkbook.Activate
Set rng2 = .InputBox("Select paste cell", "Paste where", , , , , , 8)
End With
'copy\paste values & formats
rng1.Copy
rng2.PasteSpecial (xlPasteFormulasAndNumberFormats)
rng2.PasteSpecial (xlPasteValues)
wb.Close False 'close without saving
Exit Sub

handling:
MsgBox "nothing selected"
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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