0
我有一个关于使用VBScript将memofield从“纯文本”更改为“富文本”的问题,我在这里和在互联网上发现了一些解决方案,但是所有的解决方案都是针对VBScript的。我尝试通过Windows启动一个vbscript,但我的脚本不起作用。我很喜欢VBScripting,所以我希望你们能帮助我。我以前从论坛的例子为我的脚本: How to convert a text field in an Access table to a rich text memo using VBA使用VBScript将备忘录字段从“纯文本”更改为“富文本”
我的脚本:
Dim db
Dim tdf
Dim fld1
Dim fld2
Set accessApp = GetObject("D:\test.mdb")
Set accessApp = CreateObject("Access.Application")
accessApp.OpenCurrentDataBase "D:\test.mdb", true
accessApp.visible = false
accessApp.UserControl = true
Set accessApp.db = CurrentDB
Set accessApp.tdf = db.TableDefs("Database")
Set accessApp.fld1 = tdf.Fields("Name_Memofield1")
Set accessApp.fld2 = tdf.Fields("Name_Memofield2")
Debug.Print "acTextFormatPlain: " & acTextFormatPlain & _
"; acTextFormatHTMLRichText: " & acTextFormatHTMLRichText
With fld1.Properties("TextFormat")
Debug.Print "TextFormat: " & .Value
If .Value = acTextFormatPlain Then
.Value = acTextFormatHTMLRichText
Debug.Print "TextFormat changed to: " & .Value
End If
End With
With fld2.Properties("TextFormat")
Debug.Print "TextFormat: " & .Value
If .Value = acTextFormatPlain Then
.Value = acTextFormatHTMLRichText
Debug.Print "TextFormat changed to: " & .Value
End If
End With
什么occures告诉我,问题是出在“设置accessApp.db = CurrentDB”错误的错误,发生的是:“对象不支持此属性或方法accessApp.db”如果我将“accessApp.db”更改为“db”,则发生其他错误:“Object required:'CurrentDB'”
来自访问数据库的代码不会直接作为vbs脚本文件工作。您需要通过连接字符串连接到Ms Access DB,然后编写将PlainText转换为RichText的逻辑。 –
你有一些不必要的行。尝试'Set db = accessApp.OpenCurrentDataBase“D:\ test.mdb”,true'并跳过'Set accessApp.db = CurrentDB',你不需要它。数据库不是Access应用程序的属性。请参阅https://msdn.microsoft.com/en-us/library/office/jj250267.aspx – Fionnuala
@MukulVarshney,这是不正确的。您可能无法使用ADODB连接更改字段类型,但可以使用Access应用程序对象。 – Fionnuala