我现在在做一个操作:将一个数据库里面的数据往Word的网格里面写,不知道怎么样的字符串中间加入"TAB"可以让网格自动填充,并换行,各位知道这个答案的兄弟,快点救命!
示例如下:
Dim CreateWordSheet As Object
Set CreateWordSheet = CreateObject("word.application")
CreateWordSheet.Documents.Open strDocPath, , False, , , , False
With CreateWordSheet
strValue = strValue & TAB & "ASAS" & TAB & "sdsd"
.ActiveDocument.Bookmarks("ASASA").Select
.Selection = strValue
END With
这里的这个"TAB"怎么样写进WORD会是键盘的TAB功能,谢谢知道的兄弟赐教!
8 个解决方案
#1
strValue = strValue & Vbtab & "ASAS" & Vbtab & "sdsd"
#2
TAB 在vb里面是用关键字 vbtab 表示的
楼上说的已经明白了,我就不说了,接分!
楼上说的已经明白了,我就不说了,接分!
#3
同上
strValue = strValue & vbTab & "ASAS" & vbTab & "sdsd"
strValue = strValue & vbTab & "ASAS" & vbTab & "sdsd"
#4
或者:
strValue = strValue & Chr(9) & "ASAS" & Chr(9) & "sdsd"
strValue = strValue & Chr(9) & "ASAS" & Chr(9) & "sdsd"
#5
如果是这么简单就好了,这种写法是在生成的字符串中产生了一个TAB,但是不是在填充Word的时候Word遇到一个TAB就执行本身的跳行操作啊!!!
#6
那直接在表格的单元格里写内容,写完一个后让光标移动到下一个单元格再写......
Private Sub Command6_Click()
' On Error Resume Next
Dim docApp As Object
Dim docDocument As Object
Set docApp = CreateObject("Word.Application")
docApp.Visible = True
Set docDocument = docApp.Documents.Open(App.Path & "\Test.doc")
Set docTable = docDocument.Tables(1)
'******************************
docTable.Cell(1, 1).Select
docApp.Selection.Text = "ASAS"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "sdsd"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "dfdf"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "fgfg"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "ghgh"
'......
'******************************
Set docApp = Nothing
Set docDocument = Nothing
End Sub
Private Sub Command6_Click()
' On Error Resume Next
Dim docApp As Object
Dim docDocument As Object
Set docApp = CreateObject("Word.Application")
docApp.Visible = True
Set docDocument = docApp.Documents.Open(App.Path & "\Test.doc")
Set docTable = docDocument.Tables(1)
'******************************
docTable.Cell(1, 1).Select
docApp.Selection.Text = "ASAS"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "sdsd"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "dfdf"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "fgfg"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "ghgh"
'......
'******************************
Set docApp = Nothing
Set docDocument = Nothing
End Sub
#7
如果你要填充的数据已经放到一个字符串里了,那么先把字符串的数据分解到数组里,再用上面的方法把数组的数据填充到表格里
#8
谢谢faysky2() 的方法,这种方法比较可行!
#1
strValue = strValue & Vbtab & "ASAS" & Vbtab & "sdsd"
#2
TAB 在vb里面是用关键字 vbtab 表示的
楼上说的已经明白了,我就不说了,接分!
楼上说的已经明白了,我就不说了,接分!
#3
同上
strValue = strValue & vbTab & "ASAS" & vbTab & "sdsd"
strValue = strValue & vbTab & "ASAS" & vbTab & "sdsd"
#4
或者:
strValue = strValue & Chr(9) & "ASAS" & Chr(9) & "sdsd"
strValue = strValue & Chr(9) & "ASAS" & Chr(9) & "sdsd"
#5
如果是这么简单就好了,这种写法是在生成的字符串中产生了一个TAB,但是不是在填充Word的时候Word遇到一个TAB就执行本身的跳行操作啊!!!
#6
那直接在表格的单元格里写内容,写完一个后让光标移动到下一个单元格再写......
Private Sub Command6_Click()
' On Error Resume Next
Dim docApp As Object
Dim docDocument As Object
Set docApp = CreateObject("Word.Application")
docApp.Visible = True
Set docDocument = docApp.Documents.Open(App.Path & "\Test.doc")
Set docTable = docDocument.Tables(1)
'******************************
docTable.Cell(1, 1).Select
docApp.Selection.Text = "ASAS"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "sdsd"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "dfdf"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "fgfg"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "ghgh"
'......
'******************************
Set docApp = Nothing
Set docDocument = Nothing
End Sub
Private Sub Command6_Click()
' On Error Resume Next
Dim docApp As Object
Dim docDocument As Object
Set docApp = CreateObject("Word.Application")
docApp.Visible = True
Set docDocument = docApp.Documents.Open(App.Path & "\Test.doc")
Set docTable = docDocument.Tables(1)
'******************************
docTable.Cell(1, 1).Select
docApp.Selection.Text = "ASAS"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "sdsd"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "dfdf"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "fgfg"
docApp.Selection.MoveRight wdCell
docApp.Selection.Text = "ghgh"
'......
'******************************
Set docApp = Nothing
Set docDocument = Nothing
End Sub
#7
如果你要填充的数据已经放到一个字符串里了,那么先把字符串的数据分解到数组里,再用上面的方法把数组的数据填充到表格里
#8
谢谢faysky2() 的方法,这种方法比较可行!