4 Replies - 912 Views - Last Post: 08 February 2013 - 07:19 AM Rate Topic: -----

#1 nurul elena  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Combine open file dialog with excel to flexgrid

Posted 06 February 2013 - 07:21 PM

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:

This post has been edited by GunnerInc: 06 February 2013 - 07:23 PM
Reason for edit:: Added elusive code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Combine open file dialog with excel to flexgrid

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5469
  • View blog
  • Posts: 11,749
  • Joined: 02-June 10

Re: Combine open file dialog with excel to flexgrid

Posted 07 February 2013 - 12:58 PM

Your assignment is to do this in VB6? You're deliberately going to school to learn a language that's been dead for a decade? Should this be moved to VB.NET?

Please read: This is not the VB.NET forum
Please read: Is learning VB6 now a complete waste of time?

I wrote a tutorial for OpenFileDialog. Its in C# but its really all about the properties of the control so you shouldn't have much problem learning from it, then applying that to VB.NET

http://www.dreaminco...1&#entry1397502
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3334
  • View blog
  • Posts: 11,302
  • Joined: 12-December 12

Re: Combine open file dialog with excel to flexgrid

Posted 07 February 2013 - 01:23 PM

If you want to load a FlexGrid with data from Excel there were a number of tutorials for this when I Googled.

http://www.planetsou...=61399&lngWId=1
Was This Post Helpful? 1
  • +
  • -

#4 nurul elena  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Re: Combine open file dialog with excel to flexgrid

Posted 07 February 2013 - 07:26 PM

thanks guys....
tlhIn`toq i didn't know that vb 6 is already outdated..
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5469
  • View blog
  • Posts: 11,749
  • Joined: 02-June 10

Re: Combine open file dialog with excel to flexgrid

Posted 08 February 2013 - 07:19 AM

'already'?? It went end-of-life in 2008. Which means it was dead in the real world at least a few years before that. So... it died about 10 years ago, give or take.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1