Hey guys, I've been working on this all day and cant seem to find a lot of information online.
I'm working on a project where we have a worksheet that requires us to enter our estimates into the sheet. Im trying to create code to press a command button in excel that will allow you to browse your computer, find the file, insert it as an object and then read a specific range from the embedded workbook into the main worksheet. I've slowly built the following code, but I've hit a brick wall and I dont know how to correctly grab the information that i need.
Does anyone have any suggestions?
'Insert Total Estimate Workbook into Estimate Worksheet
Private Sub CommandButton1_Click()
Dim TotalEstimateFilePath As Variant, FileName As Variant, FileLink As Variant
Dim TotalEstimateFile As Object
Application.ScreenUpdating = False 'Speeds up program by preventing screen flickering
'FileName = "Total Estimate"
TotalEstimateFilePath = Application.GetOpenFilename(FileFilter:="Microsoft Excel files(*.xls),*.xls", Title:="Total Estimate Excel File")
If TotalEstimateFilePath = False Then
MsgBox ("No file chosen")
Exit Sub
End If
Worksheets("Estimate").Range("H1").Select 'To place inserted object in the correct place on a protected sheet
Set TotalEstimateFile = Worksheets("Estimate").OLEObjects.add(FileName:=TotalEstimateFilePath, Link:=False, DisplayAsIcon:=True)
'These were some old trials to name the inserted object that keep failing, this is a small side problem that i'm going to focus on later
'ClassType:="TotalEstimateFile", IconFileName:=FileName, IconLabel:=FileName, TotalEstimateFile.Name = "Total Estimate"
For i = 1 To 27
Worksheets("Estimate").Range("I11").Offset(i - 1, 0) = xlobject.TotalEstimateFile.ActiveSheet("Contracting Sales Calculator WS").Range("A11").Offset(i - 1, 0)
Next i
Application.ScreenUpdating = True 'restart updating screen
End Sub
Let me know if i need to clarify anything above, this is my first time posting on this website.
Bookmarks