After trying your suggestions and succeeding I modified it to incorporate what I wanted the macro to do. I modified the date string in columns A6:A58 to show the last 52 weeks Friday dates and then copied it with Ctrl-C. I then ran the macro that starts on worksheet 6 as follows:
Code: Select all
REM ***** BASIC *****
' This macro is named NewFridayDate
' My OS is Linuxmint 20.3 Mate 64 Bit
' I run Nordvpn. I use Apache Openoffice 4.1.13
' Please read the information at the end of this macro
' Explanation at end of macro
Option Explicit
sub Main
' ----------------------------------------------------------------------
' define variables
Dim document as object
Dim dispatcher as object
Dim sheets as string
' get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
sheets = ThisComponent.sheets ' get the sheets of the document
Dim II as Integer
Dim Strt_Ws as Integer
Frst_Ws = 6 'worksheet counting starts at 0
' MsgBox(Frst_Ws)
for II = 0 to ThisComponent.sheets.getcount -1 ' go through them all
MsgBox(II)
'TEST sheets.getbyindex(II).getCellRangeByName("A6").string = "Hi there" 'get the cell and add next
Dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "ToPoint"
args4(0).Value = "$A$6"
' macro stops here:
' BASIC runtime error.
' An exception occurred
' Type: com.sun.start.lang.illegalArgumentException
' Message: sequence element is not assignable by given value!.
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args4())
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
' set the A column to the optimal width
Dim args109(0) as new com.sun.star.beans.PropertyValue
args109(0).Name = "aExtraWidth"
args109(0).Value = 254
dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, args109())
dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
Dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "ToPoint"
args7(0).Value = "$A$58"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args7())
Next
end sub
' This is an explanation of how to use this macro and what it does. ' Every spreadsheet that has a list of Friday
' dates can use this macro ' to update the list. The Friday date list is located in Column A, ' Rows 6:58 which has
' dates for a year, 52 Fridays. Each week in the Friday date list must be moved up one row and row 58 will receive
' the current Friday date. First, you must manually update the date list in spreadsheet $CA with the following
' commands after opening the spreadsheet:
' Click on Column A, Row 7 while holding down the cursor: Slide down ' to Column A, Row 58 to hilight the row:
' Type Ctrl-C to copy the row:' Move the cursor to Column A, Row 6 and type Ctrl-V to paste the row to start on
' Row 6: Move the cursor to Column A, Row 58 and type the current or next Friday date: Save the spreadsheet
' Click on the next spreadsheet that follows the named daily spreadsheets if they exist, otherwise, it could be named ' "SUMMARY". In any case, it should have a Friday date list in column A, Rows 6:58.' This is where you can run
' this macro to update all the worksheets in this spreadsheet. A loop should open each worksheet from the current
' worksheet and update the Friday date list in Column A, Rows 6:58. The cursor should end up on Column A, Row
' 58 and the spread sheet will be saved before moving to the next worksheet. When the last worksheet has been
' updated the macro will end.
The added part was created by Tools>Record Macro. I'm just trying to keep it simple but it doesn't work inside the loop. That is my main problem. If I had my druthers, I'd start this macro to in the first worksheet (0), make the changes, then execute the do loop, and simply copy from worksheet(0) columnA6:A58 to all the other worksheets. My goal is to stop having to select by clicking on Tools>Macros>Run Macros>Standard>NewFridayDate for each worksheet. I have another spreadsheet with 170 worksheets so you can see why this is important to me. By the way, I used to program in FORTRAN but after retiring is use PERL for everything now. Anyway that's where I'm at now. I really appreciate your help and your knowlege and I hope I'm not taking up much of your time. Thanks.