Excel-Workbook öffnen, Satz in Zelle schreiben

...und Workbook wieder schließen

Excel-Workbook öffnen, Satz in Zelle schreiben via Type, Function
Prozedur im Formular
Private Sub Form_Load()
Dim colu As Byte
Dim rw As Byte
Dim ef1 As New ExcelFile
With ef1 Aufruf der Funktionen.
.OpenFile "vbtest.xls" Workbook "unsichtbar" öffnen.
.EWriteInteger 1, 1, 100 Zu schreibender String: Positionen Row u. Col, sowie String.
.EWriteString 1, 2, "Test writing a string" Zu schreibender String: Positionen Row u. Col, sowie String.
.CloseFile Wb nach Input schließen.
End With
End
End Sub
Prozedur im Klassenmodul
Private Type BOF Beginning Of File record.
opcode1 As Byte
opcode2 As Byte
length1 As Byte
length2 As Byte
version1 As Byte
version2 As Byte
ftype1 As Byte
ftype2 As Byte
End Type
Private Type EOF End Of File record.
opcode1 As Byte
opcode2 As Byte
length1 As Byte
length2 As Byte
End Type
Private Type tInteger Integer record.
opcode1 As Byte
opcode2 As Byte
length1 As Byte
length2 As Byte
row1 As Byte
row2 As Byte
col1 As Byte
col2 As Byte
rgbattr1 As Byte
rgbAttr2 As Byte
rgbAttr3 As Byte
w1 As Byte
w2 As Byte
End Type
Private Type tLabel Label (Text) record.
opcode1 As Byte
opcode2 As Byte
length1 As Byte
length2 As Byte
row1 As Byte
row2 As Byte
col1 As Byte
col2 As Byte
rgbattr1 As Byte
rgbAttr2 As Byte
rgbAttr3 As Byte
length As Byte
End Type
Dim fhFile As Integer
Dim bof1 As BOF
Dim eof1 As EOF
Dim l1 As tLabel
Dim i1 As tInteger
Public Sub OpenFile(ByVal FileName As String)
fhFile = FreeFile
Open FileName For Binary As #fhFile
Put #fhFile, , bof1
End Sub
Public Sub CloseFile()
Put #fhFile, , eof1
Close #fhFile
End Sub
Private Sub Class_Initialize() Set up default values for records. These should be the
With bof1 values that are the same for every record.
.opcode1 = 9
.opcode2 = 0
.length1 = 4
.length2 = 0
.version1 = 2
.version2 = 0
.ftype1 = 10
.ftype2 = 0
End With
With eof1
.opcode1 = 10
End With
With l1
.opcode1 = 4
.opcode2 = 0
.length1 = 10
.length2 = 0
.row2 = 0
.col2 = 0
.rgbattr1 = 0
.rgbattr1 = 0
.rgbattr1 = 0
.length = 2
End With
With i1
.opcode1 = 2
.opcode2 = 0
.length1 = 9
.length2 = 0
.row1 = 0
.row2 = 0
.col1 = 0
.col2 = 0
.rgbattr1 = 0
.rgbAttr2 = 0
.rgbAttr3 = 0
.w1 = 0
.w2 = 0
End With
End Sub
Function EWriteString(r As Byte, c As Byte, t As String)
Dim b As Byte, l As Byte, a%
Dim StringToWrite$
StringToWrite = t
l = Len(StringToWrite)
l1.length = l Length of the text portion of the record.
l1.length1 = 8 + l Total length of the record.
l1.row1 = r - 1 BIFF counts from zero.
l1.col1 = c - 1
Put #fhFile, , l1 Put record header.
For a = 1 To l Then the actual string data.
b = Asc(Mid$(StringToWrite, a, 1))
Put #fhFile, , b
Next
End Function
Function EWriteInteger(r As Byte, c As Byte, i As Long)
With i1
.row1 = r - 1
.col1 = c - 1
.w1 = i - (Int(i / 256) * 256)
.w2 = Int(i / 256)
End With
Put #fhFile, , i1
End Function

Mehr Tipps: Textdatei im Binärmodus zum Lesen öffnen, bearbeiten und speichern I

Sponsoren und Investoren

Sponsoren und Investoren sind jederzeit herzlich willkommen!
Wenn Sie die Information(en) auf dieser Seite interessant fanden, freuen wir uns über eine kleine Spende. Empfehlen Sie uns bitte auch in Ihren Netzwerken (z. B. Twitter, Facebook oder Google+). Herzlichen Dank!

Nach oben Sitemap
Impressum & Kontakt