Results 1 to 3 of 3

Thread: [RESOLVED] another Excell Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    164

    Resolved [RESOLVED] another Excell Question

    1 time you know it, then an error or it do nothing...... can someone tell me what is wrong with my code?

    problem: i cant print my msflexgrid into excell in sheet no.2

    Code:
    Dim iRow As Long
        Dim iCol As Long
            Dim newcell As String
                Dim lastcol As Range
                Dim currentcell As Range
            Dim xls As excel.Application
        Dim XLSbook As excel.Workbook
    Dim xlssheet As excel.Worksheet
    Const xlCellTypeLastCell As Long = 11
       
    
    Set xls = New excel.Application
    Set XLSbook = xls.Workbooks.Open(App.Path & "\book1.xls")
    
    DoEvents
    
    For iRow = 0 To MSFlexGrid1.Rows - 1
        For iCol = 0 To MSFlexGrid1.Cols - 1
         MSFlexGrid1.Col = iCol
         MSFlexGrid1.Row = iRow
         newcell = Chr(iCol + 65) & iRow + 1
         xls.Worksheets("sheet1").Range(newcell).Value = Trim(MSFlexGrid1.Text)
        Next
    Next
    'AutoFormat
    xls.Selection.AutoFormat Format:=xlRangeAutoFormatList1
    
    'Center all in A
    With xls
        .Worksheets("sheet1").Columns("A:A").Select
        Selection.HorizontalAlignment = xlCenter
        End With
    
    'center all in B
    With xls
       .Worksheets("sheet1").Columns("B:B").Select
        .Selection.HorizontalAlignment = xlCenter
    End With
    
    'Center all in E
    xls.Worksheets("sheet1").Columns("E:E").Select
            With xls.Selection
            .HorizontalAlignment = xlCenter
            End With
            xls.Selection.Style = "Currency"
    
    'last column of E put the lblfishvalue
       Range("E1").SpecialCells(xlCellTypeLastCell).Offset(1) = lblFishValue.Caption
        Range("D1").SpecialCells(xlCellTypeLastCell).Offset(0, -1).Value = "Fish Value Total ="
    
    'for sheet 2
    DoEvents
    For iRow = 0 To FrmCharges.MSFlexGrid1.Rows - 1
        For iCol = 0 To FrmCharges.MSFlexGrid1.Cols - 1
         MSFlexGrid1.Col = iCol
         MSFlexGrid1.Row = iRow
         newcell = Chr(iCol + 65) & iRow + 1
         xls.Worksheets("sheet1").Range(newcell).Value = Trim(FrmCharges.MSFlexGrid1.Text)
        Next
    Next
    
    'Save workBook as ReadOnly File with password
    
    XLSbook.SaveAs ("C:\Documents and Settings\coa\My File.xls"), , , ("123"), (True), , (xlShared), (xlUserResolution)
    
    'show excel book
    xls.Visible = True
    
    
    'close
    Set XLSbook = Nothing
    Set xls = Nothing
    i added this and it do nothing, no errors just it does not do a single thing...
    Code:
    DoEvents
    For iRow = 0 To FrmCharges.MSFlexGrid1.Rows - 1
        For iCol = 0 To FrmCharges.MSFlexGrid1.Cols - 1
         MSFlexGrid1.Col = iCol
         MSFlexGrid1.Row = iRow
         newcell = Chr(iCol + 65) & iRow + 1
         xls.Worksheets("sheet2").Range(newcell).Value = Trim(FrmCharges.MSFlexGrid1.Text)
        Next
    Next

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    164

    Re: another Excell Question

    oops, my bad i got it now.... lol... i mistype here, and forgot about activating the sheet2...

    Code:
    xls.Sheets("sheet2").Activate
    'for sheet2
    DoEvents
    For iRow = 0 To FrmCharges.MSFlexGrid1.Rows - 1
        For iCol = 0 To FrmCharges.MSFlexGrid1.Cols - 1
         FrmCharges.MSFlexGrid1.Col = iCol
         FrmCharges.MSFlexGrid1.Row = iRow
         newcell = Chr(iCol + 65) & iRow + 1
         xls.Worksheets("sheet2").Range(newcell).Value = Trim(FrmCharges.MSFlexGrid1.Text)
        Next
    Next

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    164

    Re: [RESOLVED] another Excell Question

    lol, too much info going into my head and sometimes i got confused, i am also studying CDO reference, because i think i can do alot on it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width