如何将 Excel VBA 宏移植到 OpenOffice 宏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22014812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:07:32  来源:igfitidea点击:

How to port Excel VBA macro to OpenOffice macro?

excelvbaexcel-vbaopenoffice.org

提问by

How to port Excel VBA macro to OpenOffice macro?

如何将 Excel VBA 宏移植到 OpenOffice 宏?

Here is macro for creating hyperlinks:

这是用于创建超链接的宏:

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

I tried convert this macro to OpenOffice macro (using http://www.business-spreadsheets.com/vba2oo.asp)

我尝试将此宏转换为 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()
Dq = Chr(34)
For Each r In Selection
r.Formula = "=HYPERLINK(" & Dq & "http://" & r.Text & Dq & ";" & Dq & r.Text & Dq & ")"
Next r
End Sub

But got errors: BASIC syntax error: Unexpected symbol: Dim., Expected:,.

但有错误:BASIC syntax error: Unexpected symbol: Dim.Expected:,.

Replacing Dim with comma not help. How to make it work in OpenOfffice?

用逗号替换 Dim 无济于事。如何让它在 OpenOffice 中工作?

采纳答案by

Solution:

解决方案:

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