Help me! I just can't seem to get this right. I'm trying to open an Excel file(Template) and put data from msflexgrid into a specific place in the excel file but i just can't seem to get it right. Can anyone help me with this coding? Much appreciated. Thank you in advance.

P/S: The "for" loops below are correct.

Private Sub cmdEXCEL_Click()

On Error Resume Next
    Dim exc As Object
    Dim objworkbook As Object
    Dim i, n As Integer
    Open App.Path & " " For Output As exc
    Set exc = OpenObject("Excel.Application")
    

For i = 1 To 1
    
    MSFlexGrid1.Col = i
    
    For n = 0 To MSFlexGrid1.Row
            
        MSFlexGrid1.Col = n
        objworkbook.activesheet.cells(n + 15, i + 2).value = MSFlexGrid1.Text

    Next
Next


For i = 2 To 6
    
    MSFlexGrid1.Col = i
    
    For n = 0 To MSFlexGrid1.Row
            
        MSFlexGrid1.Col = n
        objworkbook.activesheet.cells(n + 15, i + 15).value = MSFlexGrid1.Text

    Next
Next
    
    
    exc.Visible = True
    Set exc = Nothing
End Sub

I've tried doing it a plenty of times with multiple ways but I still can't do it. Thank you so much.

There might be a problem with the for loops because it only reads "column 1,row ten".

Please see my reply at your new post. Their is a link posted that gives you the exact code for achieving this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.