Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Combine open file dialog with excel to flexgrid

$
0
0
hye...
i have this code...works well..but how can i combined open file
dialog and excel to flexgrid code?so it didn't open only specific file


Private Sub command1_click()
  
    [color="#0000FF"]CommonDialog1.Filter = "excel Files (*.xls)|*.xls|All " & _
    "Files (*.*)|*.*"
    CommonDialog1.DialogTitle = "Select File"
    CommonDialog1.ShowOpen[/color]
      
Dim xlObject As Excel.Application
Dim xlWB As Excel.Workbook
        
    Set xlObject = New Excel.Application
    [color="#0000FF"]Set xlWB = xlObject.Workbooks.Open("D:\others\Book1.xls") 'Open your book here[/color]

    Clipboard.Clear
    With xlObject.ActiveWorkbook.ActiveSheet
        .Range("A1:G50").Copy 'Set selection to Copy
    End With
       
    With MSFlexGrid1
        .Redraw = False     'Dont draw until the end, so we avoid that flash
        .Row = 0            'Paste from first cell
        .Col = 0
        .RowSel = .Rows - 1 'Select maximum allowed (your selection shouldnt be greater than this)
        .ColSel = .Cols - 1
        .Clip = Replace(Clipboard.GetText, vbNewLine, vbCr) 'Replace carriage return with the correct one
        .Col = 1            'Just to remove that blue selection from Flexgrid
        .Redraw = True      'Now draw
    End With
        
    xlObject.DisplayAlerts = False 'To avoid "Save woorkbook" messagebox
    
    'Close Excel
    xlWB.Close
    xlObject.Application.Quit
    Set xlWB = Nothing
    Set xlObject = Nothing
     
End Sub


*** Edit ***
Please use code tags when posting code
:code:

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>