Forum

Opening an excel fi...
 
Notifications
Clear all

Opening an excel file in the same worksheet and closing it too using VBA

2 Posts
2 Users
0 Reactions
110 Views
(@akansh2196)
Posts: 11
Eminent Member
Topic starter
 

Sir/Mam,

I have written a code that opens an excel file based upon the path provided, but the new excel get open as a new worksheet,  Can it be opened as another sheet in the same workbook?

Kindly help me with the modification  in the code as attached. Cell D4 contains the address of the file that i want to open.

 

Sub work()

Dim my as string

my=range("d4").value

Workbooks.open my

Activeworkbook.close

end sub

 

 

Regards. 

 
Posted : 23/09/2020 9:40 am
(@purfleet)
Posts: 412
Reputable Member
 

Its much easier if you add a workbook rather than paste in a peice of code

Add ActiveSheet.Move before:=Workbooks("OpenFile.xlsm").Sheets(1) after you open in and delete the activeworkbook.close

Sub work()

Dim my As String

my = Range("d4").Value

Workbooks.Open my

ActiveSheet.Move before:=Workbooks("OpenFile.xlsm").Sheets(1)

'ActiveWorkbook.Close

End Sub

 
Posted : 23/09/2020 4:23 pm
Share: