Opening Another Workbook

dani023

New Member
Joined
Oct 14, 2016
Messages
1
Hello! I'm fairly new to VBA coding (and this site), and I'm having a little problem that I'm hoping someone can help me with. I'm trying to get my workbook to open up a second workbook that is saved on the user's desktop and copy information into that second workbook. I found code in a different thread on this site, and was able to tweak it to get it to work. The code works perfectly on my computer, but if I try to send the workbooks to another user it fails. I make sure the user has the workbooks saved to their desktop and documents to be safe. However, it still doesn't work. This is the code that I'm using:

Code:
Sub work()
 
Dim Vfile As Variant
Dim wbTarget As Workbook
Dim wsTarget As Worksheet
Dim wbFrom As Workbook
Dim wsFrom As Worksheet
 
 
 
 
Set wbFrom = ActiveWorkbook
Set wsFrom = Sheets("Log")
 
 
    '-------------------------------------------------------------
    'Open file with data to be copied
    
  Workbooks.Open Filename:=ThisWorkbook.Path & "\Workbook A.xlsm"
  
  Set wbTarget = Workbooks("Workbook A.xlsm")
    Set wsTarget = wbTarget.Worksheets("Survey")
 
    
   wsFrom.Range("A2").Copy
    wsTarget.Range("C2").PasteSpecial Paste:=xlPasteValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
   wsFrom.Range("C2").Copy
    wsTarget.Range("B2").PasteSpecial Paste:=xlPasteValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
    'Close file that was opened
    wbTarget.Close SaveChanges:=True
 
 
    
End Sub

The error the user receives gives a string of numbers, and then says that the file path is not found. Is there a way to get the above code to open a relative file name versus a fixed one? I have to send this file out to 10+ people, and would prefer not having to manually enter in each user's individual file path.

Any help that anyone could provide would be greatly appreciated.

Thank you!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This is most likely the culprit.

Code:
Workbooks.Open Filename:=[COLOR=#b22222]ThisWorkbook.Path [/COLOR]& "\Workbook A.xlsm"

The workbook the user is using to host the code could be saved to a default directory on a LAN or the Web. I suspect that since the error message number was a string of numbers it could be the web. If you make the path to open the second workbook equal the path where the file is stored then it should work OK.

Code:
Dim myPath As String
myPath = "C:\User\Desktop\"
Workbooks.Open myPath & "Workbook A.xlsm"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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