PDA

View Full Version : word در vb



hastyar
پنج شنبه 11 تیر 1388, 00:22 صبح
بچه ها من می خوام از طریق ویژوال به فایل wordدسترسی داشته باشم کسی می تونه کمکم کنه؟؟؟؟؟؟؟؟؟؟؟؟؟خیلی برام مهم لطفاً زود جواب بدید

butterfly8528
پنج شنبه 11 تیر 1388, 02:00 صبح
سلام دوست عزیز .

این پروژه حتما کمکت میکنه :بامزه:

موفق باشی .

hastyar
جمعه 12 تیر 1388, 00:20 صبح
ببخشید جسارتاً اینو با چه نسخه ای از vbنوشتید من با vb 6نتونستم بازش کنم
و اینکه بگید از این چطور در پروژم استفاده کنم

alih110
جمعه 12 تیر 1388, 00:31 صبح
منم همینطور نتونستم .

M_P_1374
جمعه 12 تیر 1388, 09:35 صبح
اینم سورس اون پروژه ای که در پست دوم ارسال شده
یه دونه کامپوننت MS Flex Grid روی فرمتون بذارین با یدونه دکمه + یه Refrence که متعلق به Microsoft Word هست و از این کد استفاده کنید


Private Sub Command1_Click()
'Early object binding
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range
'Uncomment below for late object binding
'Dim oWord As Object
'Dim oDoc As Object
'Dim oRange As Object
Dim row As Integer
Dim col As Integer
Dim i As Integer
Dim n As Integer
Dim sTemp As String
Dim arr() As String

ReDim arr(MSFlexGrid1.Rows - 1, MSFlexGrid1.Cols - 1)

'Create an instance of Word
Set oWord = CreateObject("Word.Application")

'Show Word to the user
oWord.Visible = True

'Add a new, blank document
Set oDoc = oWord.Documents.Add

'Get the current document's range object

'Store FlexGrid items to a two dimensional array
For row = 0 To MSFlexGrid1.Rows - 1
n = 0
For col = 0 To MSFlexGrid1.Cols - 1
arr(i, n) = MSFlexGrid1.TextMatrix(row, col)
n = n + 1
Next
i = i + 1
Next

'Store array items to a string
For i = LBound(arr, 1) To UBound(arr, 1)
For n = LBound(arr, 2) To UBound(arr, 2)
sTemp = sTemp & arr(i, n)
If n = UBound(arr, 2) Then
sTemp = sTemp & vbCrLf
Else
sTemp = sTemp & vbTab
End If
Next
Next

'get the current document's range object and move to end of document
Set oRange = oDoc.Bookmarks("\EndOfDoc").Range

oRange.Text = sTemp

'convert the text to a table and format the table
oRange.ConvertToTable vbTab, Format:=wdTableFormatColorful2

Set oRange = Nothing

End Sub

Private Sub Form_Load()
Dim i As Integer
Dim n As Integer
'populate FlexGrid
With MSFlexGrid1
.Rows = 1
.Cols = 4
.ColWidth(1) = 1100
.ColWidth(2) = 1100
.ColWidth(3) = 1100
'Add field headers
For i = 1 To 3
.col = i
.Text = "Col " & i
Next
'Add data
For i = 1 To 15
.Rows = .Rows + 1
.row = .Rows - 1
.col = 0
.Text = "Row " & i
For n = 1 To 3
.col = n
.Text = "Row " & i & ",Col " & n
Next
Next
End With

End Sub