ترجمه و تحلیل این کد

Collapse
X
 
  • زمان
  • نمایش
حذف همه
new posts
  • alisabet

    • 2011/09/08
    • 159
    • 45.00

    ترجمه و تحلیل این کد

    با سلام خدمت اساتید گرامی :

    در کد زیر یادداشتی هست مبنی بر این " فراموش نکنید فایل اکسل ساخته شده را نمی توانید باز کنید تا زمانیکه کامپیوتر را ریستارت نکردید" سوال من اینست که چرا ؟ چرا نمیتوان فایل را باز کرد



    کد PHP:
    'do declare these variables you need to add a reference
    '
    to the microsoft excel 'xx' object library

    'you need two text boxes and two command buttons
    '
    on the forman excel file in c:\book1.xls 

    Dim xl 
    As New Excel.Application
    Dim xlsheet 
    As Excel.Worksheet
    Dim xlwbook 
    As Excel.Workbook 

    Private Sub Command1_Click()
    'the benifit of placing numbers in (row, col) is that you
    '
    can loop through different directions if requiredI could
    'have used column names like "A1" 'etc

        
    Text1.Text xlsheet.Cells(21' row 2 col 1
        Text2.Text = xlsheet.Cells(2, 2) ' 
    row 2 col 2 

    'don't forget to do this or you'll not be able to open
    '
    book1.xls againuntill you restart you pc.
        
    xl.ActiveWorkbook.Close False"c:\book1.xls"
        
    xl.Quit
    End Sub 

    Private Sub Command2_Click()
        
    xlsheet.Cells(21) = Text1.Text
        xlsheet
    .Cells(22) = Text2.Text
        xlwbook
    .Save 

    'don't forget to do this or you'll not be able to open
    '
    book1.xls againuntill you restart you pc.
        
    xl.ActiveWorkbook.Close False"c:\book1.xls"
        
    xl.Quit
    End Sub 

    Private Sub Form_Load()
        
    Set xlwbook xl.Workbooks.Open("c:\book1.xls")
        
    Set xlsheet xlwbook.Sheets.Item(1)
    End Sub 

    Private Sub Form_Unload(Cancel As Integer)
        
    Set xlwbook Nothing
        Set xl 
    Nothing
    End Sub 
چند لحظه..