-
Using Excel
I have designed a small software that, after user input, exports all the data into a template Excel File that has all the report format pre edited. (i dont want to use the report feature as i want this data in Excel). I have already written the code for exporting and it works fine.
In a day around 5 such reports will be printed. But the problem is that once this data is exported i want it to automatically use the "Save As" function instead of save and it shud save in pre-set location and i shud have access to the name property of the file so that an input box pops up asking the name, whatever i type in that shud be the name of the file and it shud go to the pre-set location and it shud be a new instance of the template so that the original template is still there for further use.
Ive never worked in VBA before so im a lil weak in this, someone please guide me.
Thank You :)
-
Re: Using Excel
it wouldn't be in vba. you'd write it in vb after your exporting.
we need to see your export code...
-
Re: Using Excel
This is the code that i have used to create and export.. Now i need to work on saving it..
Code:
Dim MatchExcel As New Excel.Application
MatchExcel.Workbooks.Add()
MatchExcel.Visible = True
With MatchExcel
.Range("A1").Select()
Dim numrows As Integer = 0
Do Until numrows = P1RowCount
.ActiveCell.Offset(numrows, 0).Value = DataGridView1.Item(0, numrows).Value
.ActiveCell.Offset(numrows, 1).Value = DataGridView1.Item(1, numrows).Value
.ActiveCell.Offset(numrows, 2).Value = DataGridView1.Item(2, numrows).Value
.ActiveCell.Offset(numrows, 3).Value = DataGridView1.Item(3, numrows).Value
.ActiveCell.Offset(numrows, 4).Value = DataGridView1.Item(4, numrows).Value
.ActiveCell.Offset(numrows, 5).Value = DataGridView1.Item(5, numrows).Value
.ActiveCell.Offset(numrows, 6).Value = DataGridView1.Item(6, numrows).Value
.ActiveCell.Offset(numrows, 7).Value = DataGridView1.Item(7, numrows).Value
numrows += 1
Loop
End With
-
Re: Using Excel
something like this:
Code:
Dim MatchExcel As New Excel.Application
MatchExcel.Workbooks.Add()
MatchExcel.Visible = True
With MatchExcel
.Range("A1").Select()
Dim numrows As Integer = 0
Do Until numrows = P1RowCount
.ActiveCell.Offset(numrows, 0).Value = DataGridView1.Item(0, numrows).Value
.ActiveCell.Offset(numrows, 1).Value = DataGridView1.Item(1, numrows).Value
.ActiveCell.Offset(numrows, 2).Value = DataGridView1.Item(2, numrows).Value
.ActiveCell.Offset(numrows, 3).Value = DataGridView1.Item(3, numrows).Value
.ActiveCell.Offset(numrows, 4).Value = DataGridView1.Item(4, numrows).Value
.ActiveCell.Offset(numrows, 5).Value = DataGridView1.Item(5, numrows).Value
.ActiveCell.Offset(numrows, 6).Value = DataGridView1.Item(6, numrows).Value
.ActiveCell.Offset(numrows, 7).Value = DataGridView1.Item(7, numrows).Value
numrows += 1
Loop
End With
Dim sfd As New SaveFileDialog
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
MatchExcel.Workbooks(0).SaveAs(sfd.FileName)
End If
-
Re: Using Excel
this works great but the problem is now the user needs to type the file name and select the path. The file name is already saved in the form of a string and the path is always same, so cant i integrate these two into the code so that i can eliminate the user making errors while saving, if they choose the wrong path or wrong file name it will be a problem.
Thank you :)
-
Re: Using Excel
instead of:
Code:
Dim sfd As New SaveFileDialog
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
MatchExcel.Workbooks(0).SaveAs(sfd.FileName)
End If
Code:
MatchExcel.Workbooks(0).SaveAs(path)
-
Re: Using Excel
Thank You very Much .Paul :D