如何将Excel VBA宏移植到OpenOffice宏?
这是用于创建超链接的宏:
Sub HyperMaker()
Dim r As Range
Dq = Chr(34)
For Each r In Selection
r.Formula = "=HYPERLINK(" & Dq & "http://" & r.Text & Dq & ";" & Dq & r.Text & Dq & ")"
Next r
End Sub
我尝试将此宏转换为OpenOffice宏(使用http://www.business-spreadsheets.com/vba2oo.asp)
Sub HyperMaker()
Dim r As Dim oSheet as Object[n]oSheet = ThisComponent.CurrentController.ActiveSheet[n]oSheet.getCellRangeByName($1)
Dq = Chr(34)
For Each r In Selection
r.Formula = "=HYPERLINK(" & Dq & "http://" & r.Text & Dq & ";" & Dq & r.Text & Dq & ")"
Next r
End Sub
但有错误:BASIC syntax error: Unexpected symbol: Dim.
,Expected:,.
用逗号替换Dim没有帮助。 如何使它在OpenOfffice中工作?
答案 0 :(得分:1)
Sub makeHyperlinks()
Dim sh As Object, z As Object, c As Object
Dim qCells As Object, enuCells As Object
sh = ThisComponent.Sheets.getByName("YourSheetName")
z = sh.getCellRangeByName("B1:B5") ' your column (or rectangle)
qCells = z.queryContentCells(-1)
enuCells = qCells.Cells.createEnumeration
Do While enuCells.hasMoreElements
c = enuCells.nextElement
c.Formula = "=HYPERLINK(""http://" & c.String & """)"
Loop
End Sub