PDA

View Full Version : Exporting worksheet from a closed workbook in a shared drive to another workbook



demonact
03-13-2016, 06:58 AM
Hi everyone,

Urgent help needed here. I need to import a whole worksheet(sheet1) from a closed workbook(testing) in a shared drive to another worksheet(scorecard) in another workbook(named Performance) which will be opened. This should be done by clicking a button in the worksheet named scorecard. Can anyone here kindly help me out with it?

Sub copypaste()
Workbooks.OpenText Filename:=" C:\ "
Range("A1:AZ50").Copy
Workbooks("Performance.xlsm").Activate
Sheets("scorecard").Select
Range("A1:AZ50").Select
ActiveSheet.Paste

Workbooks("testing").Close SaveChanges:=False
End Sub

Can anyone here help me out with this code? Thank you! By the way, what is the syntax in writing the filepath in VBA?

mancubus
03-14-2016, 07:27 AM
welcome to vbax.

pls use code tags as explained in my signature.

recording a macro while opening the csv file will give you correct file path and name.

play with this:


Sub vbax_55423_import_from_closed_text_file()
Workbooks.OpenText Filename:="C:\MyFolder\testing.csv"
ThisWorkbook.Worksheets("scorecard").Range("A1:AZ50").Value = ActiveSheet.Range("A1:AZ50").Value
Workbooks("testing").Close SaveChanges:=False
End Sub