Workbook to workbook info transfer with dynamic names on button

jackers15

New Member
Joined
Jun 15, 2017
Messages
5
Hi,

So I have a button set up with the following code:

Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Sub DynamicNamePull()

   Application.ScreenUpdating = False

   Dim beginPull As Action
   beginPull = pull("Settings!Q15" & "Settings!O2" & "Settings!Q16")
  
   Application.ScreenUpdating = True

End Sub
</code>

The pull function called is the following:

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Function pull(xref As String) As Variant

Dim xlapp As Object, xlwb As Workbook
Dim b As String, r As Range, c As Range, n As Long

n = InStrRev(Len(xref), xref, "")

If n > 0 Then
If Mid(xref, n, 2) = "\[" Then
b = Left(xref, n)
n = InStr(n + 2, xref, "]") - n - 2
If n > 0 Then
b = b & Mid(xref, Len(b) + 2, n)
Else
n = InStrRev(Len(xref), xref, "!")
If n > 0 Then
b = Left(xref, n - 1)
End If
If Left(b, 1) = "'" Then
b = Mid(b, 2)
On Error Resume Next
If n > 0 Then
If Dir(b) = "" Then
n = 0
Err.Clear
On Error GoTo 0
End If
If n <= 0 Then
pull = CVErr(xlErrRef)
Exit Function
End If
pull = Evaluate(xref)
If CStr(pull) = CStr(CVErr(xlErrRed)) Then
On Error GoTo CleanUp
Set xlapp = CreateObject("Excel.Application")
Set xlwb = xlapp.Workbooks.Add
On Error Resume Next
n = InStr(InStr(1, xref, "]") + 1, xref, "!")
b = Mid(xref, 1, n)
Set r = xlwb.Sheets(1).Range(Mid(xref, n + 1))
If r Is Nothing Then
pull = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, x1R1C1))
Next
pull = r.Value
End If
End If

CleanUp:
If Not xlwb Is Nothing Then
xlwb.Close 0
If Not xlapp Is Nothing Then
xlapp.Quit
Set xlapp = Nothing
End If

End Function</code>

I keep getting a mismatch '13' error. I am trying to have the button run a function to pull a cell in another closed workbook and print it in a cell in the main workbook. I have the formula: =PULL("'H:\Projects\[" & O2 & "]CoverSheet'!J15") in the first cell I need it to print to. The continuing formulas just change the O row (ex: O3, O4, etc). I am running Excel 2010.

Thanks in advance for any help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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