Encontre este codigo y me interesa utilizarlo para mi proyecto excel, el problema es que me crea automaticamente un nuevo archivo excel, lo que me gustaria hacer es que se seleccione un archivo especifico que yo elija creo que la parte del codigo en donde puedo hacerlo es esta
Set oXL = CreateObject("Excel.Application") oXL.Visible = True
Private Sub Command1_Click()
Dim oXL As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim i As Integer, j As Integer
Dim sMsg As String
' Create a new instance of Excel and make it visible.
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True
' Add a new workbook and set a reference to Sheet1.
Set oBook = oXL.Workbooks.Add
Set oSheet = oBook.Sheets(1)
' Demo standard Automation from out-of-process,
' this routine simply fills in values of cells.
sMsg = "Fill the sheet from out-of-process"
MsgBox sMsg, vbInformation Or vbMsgBoxSetForeground
For i = 1 To 100
For j = 1 To 10
sMsg = "Cell(" & Str(i) & "," & Str(j) & ")"
oSheet.Cells(i, j).Value = sMsg
Next j
Next i
' You're done with the first test, now switch sheets
' and run the same routine via an inserted Microsoft Visual Basic
' for Applications macro.
MsgBox "Done.", vbMsgBoxSetForeground
Set oSheet = oBook.Sheets.Add
oSheet.Activate
sMsg = "Fill the sheet from in-process"
MsgBox sMsg, vbInformation Or vbMsgBoxSetForeground
' The Import method lets you add modules to VBA at
' run time. Change the file path to match the location
' of the text file you created in step 3.
oXL.VBE.ActiveVBProject.VBComponents.Import "C:\KbTest.bas"
' Now run the macro, passing oSheet as the first parameter
oXL.Run "DoKbTest", oSheet
' You're done with the second test
MsgBox "Done.", vbMsgBoxSetForeground
' Turn instance of Excel over to end user and release
' any outstanding object references.
oXL.UserControl = True
Set oSheet = Nothing
Set oBook = Nothing
Set oXL = Nothing
End Sub