Click here to Skip to main content
15,887,465 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: how to print same page itself (without going report page) ? Pin
JC.KaNNaN3-Apr-09 22:40
JC.KaNNaN3-Apr-09 22:40 
GeneralRe: how to print same page itself (without going report page) ? Pin
Anubhava Dimri3-Apr-09 23:13
Anubhava Dimri3-Apr-09 23:13 
AnswerRe: how to print same page itself (without going report page) ? Pin
Mohammed.Al-Qaisi5-Apr-09 23:33
Mohammed.Al-Qaisi5-Apr-09 23:33 
Question[Message Deleted] Pin
nilleshkumar3-Apr-09 20:11
nilleshkumar3-Apr-09 20:11 
AnswerRe: help me pls urgent Pin
Christian Graus3-Apr-09 23:20
protectorChristian Graus3-Apr-09 23:20 
Questionvisual bais output written to excel Pin
jazzgirl3-Apr-09 15:27
jazzgirl3-Apr-09 15:27 
AnswerRe: visual bais output written to excel Pin
ChandraRam3-Apr-09 22:08
ChandraRam3-Apr-09 22:08 
QuestionRe: visual bais output written to excel Pin
jazzgirl4-Apr-09 6:29
jazzgirl4-Apr-09 6:29 
ChandraRam:

I have the following questions to ask you which include:

1. I am not certain of when I can use a recording macro in excel? I basically need to have the visual basic.net 2005 desktop application control the processing since it is the one the drives the generation of separate excel worksheets in distinct workbooks. (There is one worksheet per workbook since each spreadsheet is email and to differet customers.)
2. When I use the recroding macro, when it be before I create the excel object, while I am putting data into the excel object, or after the excel worksheet has been generated?
3. I am not certain where you are refering to using the VBA code. Am I including the VBA code in the following .NET code:
xlApp = New Excel.Application
xlClApp = New Excel.ApplicationClass
xlApp.Workbooks.Add()
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"),
Microsoft.Office.Interop.Excel.Worksheet)
xlApp.Visible = False
xlApp.ScreenUpdating = True
dt = ds4.Tables(0)
'Add the column headings for the from the dataset
Dim dc As DataColumn
Dim iCols As Int32 = 0
For Each dc In dt.Columns
xlWorkSheet.Range("A1").Offset(0, iCols).Value = dc.ColumnName
xlWorkSheet.Range("A1").Offset(0, iCols).Font.Bold = True
xlWorkSheet.Range("A1").Offset(0, iCols).BorderAround()
iCols += 1
Next

Dim iRows As Int32
For iRows = 0 To dt.Rows.Count - 1
xlWorkSheet.Range("A2").Offset(0, iCols).Select()
xlWorkSheet.Range("A2").Offset(0, iCols).Justify()
xlWorkSheet.Range("A2").Offset(0, iCols).WrapText = True
xlWorkSheet.Range("A2").Offset(iRows).Resize(1, iCols).Value = _
dt.Rows(iRows).ItemArray()
xlWorkSheet.Range("A2").Offset(0, iCols).BorderAround()
Next
excelFile = "c:\exceltst.xls"
xlWorkBook.Sheets("sheet1").SaveAs(excelFile)
4. How can I use VBA code here?
5. Here is my code so far:
Private Sub ShowReport_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim xlClApp As Excel.ApplicationClass
Dim excelFile As String = " "
Dim dt As DataTable
Dim da4 As SqlDataAdapter
cnn4 = New SqlConnection(connectionString)
cmd4 = New SqlCommand("stored procedure name", cnn4)
cmd4.CommandType = CommandType.StoredProcedure
With cmd4
.Parameters.Add("@parm1", SqlDbType.VarChar).Value = strParm1
.Parameters.Add("@parm2", SqlDbType.VarChar).Value = strParm2
End With
da4 = New SqlDataAdapter(cmd4)
da4.Fill(ds4)
xlApp = New Excel.Application
xlClApp = New Excel.ApplicationClass
xlApp.Workbooks.Add()
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"),
Microsoft.Office.Interop.Excel.Worksheet)
xlApp.Visible = False
xlApp.ScreenUpdating = True
dt = ds4.Tables(0)
'Add the column headings for the from the dataset
Dim dc As DataColumn
Dim iCols As Int32 = 0
For Each dc In dt.Columns
xlWorkSheet.Range("A1").Offset(0, iCols).Value = dc.ColumnName
xlWorkSheet.Range("A1").Offset(0, iCols).Font.Bold = True
xlWorkSheet.Range("A1").Offset(0, iCols).BorderAround()
iCols += 1
Next

Dim iRows As Int32
For iRows = 0 To dt.Rows.Count - 1
xlWorkSheet.Range("A2").Offset(0, iCols).Select()
xlWorkSheet.Range("A2").Offset(0, iCols).Justify()
xlWorkSheet.Range("A2").Offset(0, iCols).WrapText = True
xlWorkSheet.Range("A2").Offset(iRows).Resize(1, iCols).Value = _
dt.Rows(iRows).ItemArray()
xlWorkSheet.Range("A2").Offset(0, iCols).BorderAround()
Next
excelFile = "c:\exceltst.xls"
xlWorkBook.Sheets("sheet1").SaveAs(excelFile)
xlWorkBook.Close()
xlApp.Quit()
xlWorkSheet = Nothing
xlWorkBook = Nothing
xlClApp = Nothing
da4.Dispose()
cmd4.Dispose()
cnn4.Close()


Thanks!
QuestionWindow is slow to instantiate - only on some machines Pin
dBrong3-Apr-09 6:11
dBrong3-Apr-09 6:11 
AnswerRe: Window is slow to instantiate - only on some machines Pin
Christian Graus3-Apr-09 13:54
protectorChristian Graus3-Apr-09 13:54 
GeneralRe: Window is slow to instantiate - only on some machines Pin
dBrong3-Apr-09 15:12
dBrong3-Apr-09 15:12 
GeneralRe: Window is slow to instantiate - only on some machines Pin
Christian Graus3-Apr-09 23:20
protectorChristian Graus3-Apr-09 23:20 
AnswerRe: Window is slow to instantiate - only on some machines Pin
Luc Pattyn3-Apr-09 14:51
sitebuilderLuc Pattyn3-Apr-09 14:51 
GeneralRe: Window is slow to instantiate - only on some machines Pin
dBrong3-Apr-09 15:15
dBrong3-Apr-09 15:15 
GeneralRe: Window is slow to instantiate - only on some machines Pin
Luc Pattyn3-Apr-09 15:49
sitebuilderLuc Pattyn3-Apr-09 15:49 
QuestionHex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 4:37
Cory Kimble3-Apr-09 4:37 
AnswerRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Luc Pattyn3-Apr-09 5:05
sitebuilderLuc Pattyn3-Apr-09 5:05 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 5:55
Cory Kimble3-Apr-09 5:55 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Luc Pattyn3-Apr-09 6:48
sitebuilderLuc Pattyn3-Apr-09 6:48 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 9:33
Cory Kimble3-Apr-09 9:33 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Luc Pattyn3-Apr-09 10:05
sitebuilderLuc Pattyn3-Apr-09 10:05 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 10:55
Cory Kimble3-Apr-09 10:55 
QuestionSaveFileDialog with Serialport Pin
Quin Nee3-Apr-09 1:39
Quin Nee3-Apr-09 1:39 
AnswerRe: SaveFileDialog with Serialport Pin
Luc Pattyn3-Apr-09 3:27
sitebuilderLuc Pattyn3-Apr-09 3:27 
Questionproblem in overwriting the previous setup Pin
Pankaj Garg3-Apr-09 0:47
Pankaj Garg3-Apr-09 0:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.