davidboutche
08-07-2009, 02:18 AM
I have a word template that opens a series of userforms and processes that information in various ways
What I would like is a piece of code that takes the userform textbox contents, opens a specified excel workbook and inserts that information into the next free row.
UPDATE:
This is what I've managed to find and get working so far:
Sub CreateNewExcelWB()
' to test this code, paste it into a Word module
' add a reference to the Excel-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'Set xlWB = xlApp.Workbooks.Add ' create a new workbook
' or
Set xlWB = xlApp.Workbooks.Open("V:\pndbook.xls")
' open an existing workbook
' example excel operations
With xlWB.activesheet
Range("A1").Value = UserForm1.officerbox.Text
End With
'xlWB.Close False ' close the workbook without saving
'xlApp.Quit ' close the Excel application
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
What I need it to do now is insert a line in excel before copying the text across OR have it copy the text onto the next free line. I will eventually get it to copy more than one textbox across
What I would like is a piece of code that takes the userform textbox contents, opens a specified excel workbook and inserts that information into the next free row.
UPDATE:
This is what I've managed to find and get working so far:
Sub CreateNewExcelWB()
' to test this code, paste it into a Word module
' add a reference to the Excel-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'Set xlWB = xlApp.Workbooks.Add ' create a new workbook
' or
Set xlWB = xlApp.Workbooks.Open("V:\pndbook.xls")
' open an existing workbook
' example excel operations
With xlWB.activesheet
Range("A1").Value = UserForm1.officerbox.Text
End With
'xlWB.Close False ' close the workbook without saving
'xlApp.Quit ' close the Excel application
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
What I need it to do now is insert a line in excel before copying the text across OR have it copy the text onto the next free line. I will eventually get it to copy more than one textbox across