如何将Excel VBAmacros移植到OpenOfficemacros?

如何将Excel VBAmacros移植到OpenOfficemacros?

这里是创build超链接的macros:

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 

我试着将这个macros转换成OpenOfficemacros(使用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:,.

用逗号替代昏暗没有帮助。 如何使它在OpenOfffice中工作?

解:

 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