VBA - pass form data to new spreadsheet

Sinbad

Board Regular
Joined
Apr 18, 2012
Messages
224
Hi all,

I have a form with a button on it that, when clicked opens another spreadsheet. Works great, the question now is.. can I pass info from the from to the new spreadsheet into a specific cell ?

the value of "instno" needs to be pasted into cell C3 in the new workbook called "tracking.xlms"

thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
this is what the code for the button is.. only opens the workbook

Code:
Private Sub CMB2_Click()
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open Filename:="G:\tracking.xlsm"
End Sub
 
Upvote 0
I was thinking of declaring a public variable on form load, assigning it the value as it is read from the main workbook and then pasting it, but it does not seem to work..

declaring the public string
Code:
Public instno As String


Code:
Sub UserForm_Initialize()
instno = Cells(ActiveCell.Row, "J").Value
' other stuff in here too, this is just for this problem...
End Sub

and now for the button where it needs to past it into the other workbook
Code:
Private Sub CMB2_Click() 
Dim xlApp As Excel.Application 
Set xlApp = CreateObject("Excel.Application") 
xlApp.Visible = True xlApp.Workbooks.Open Filename:="G:\tracking.xlsm"
Cells(13, "E").Value = instno
End Sub

but somehow this does not work.. Well, I´m new to VBA, so no surprise for me ;)
 
Last edited:
Upvote 0
Code:
Private Sub CMB2_Click()
    Dim xlApp       As Excel.Application

    Set xlApp = New Excel.Application
    With xlApp
        .Visible = True
        With .Workbooks.Open(Filename:="G:\tracking.xlsm")
            .Worksheets("someSheetName").Range("C3").Value = instno
        End With
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,992
Latest member
prabhuk279

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