In Writer, I would like to search for some text and when found position the view to the top of the view/window.
Using the following code,
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.SearchString"
args1(0).Value = ":"
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())
the view changes and it shows the selection but it is not in any particular place. I want it to be at the top of the window/view.
I've also found elsewhere the use of ThisComponent.currentController.getViewData() and restoreViewData(). So I experimented and determined how to change the data returned in order to get a vertical scroll but nothing happens. For example...
vd = ThisComponent.currentController.getViewData()
vdParts = Split(vd, ";")
vdParts(6) = CLng(vdParts(6)) + 1000
vd = join(vdParts, ";")
ThisComponent.currentController.restoreViewData(vd)
Any suggestions?
PS: I am running version 5.0.5.2 on Windows 7 x64
Spreadsheets have View Panes that can be manipulated, but it does not look like there is a similar interface in Writer.
Instead, use the View Cursor to go down one or two pages, then move back to the location of the search result.
Also, do not use the dispatcher for the search. Use the API instead, like in section 7.14 of Andrew Pitonyak's macro document.
Related
I'm use Visual Basic 6 to create a table with many Textbox which named txtNo1, txtNo2, txtNo3,...
I want to use the "For...Next..." loop to assign a content to these Textbox.
How can I call all these Textbox in the simplest way?
For i = 1 to 100
txtNo (......) .txt = "ABC"
Next i
Instead of using unique textboxes, each with a unique name, you should use a (textbox) control array:
Place the 1st textbox on the form, name it 'txtNo'
Copy it and paste it onto the form
VB will ask you "There's already a control named 'txtNo'. Would you like to create a control array?". Answer "Yes"
Paste as the textbox as many times as you need it
Then your code looks like
' Control arrays typically start at index 0
For i = 0 to 100
txtNo(i) .txt = "ABC"
Next i
Jim Mack's solution works as well, code for it:
' Assuming your form is named 'Form1'
For each ctrl in Form1.Controls
If TypeOf ctrl Is Textbox
For i = 1 To 100
If ctrl.Name = "txtNo" & CStr(i) Then
ctrl.Text = "ABC"
End If
End If
End If
It's a bit more complex, but therefore more flexible as works with multiple control types (in one loop).
If you need an easiest way to create your textboxes as a table, you can Load the controls at runtime. You have to add only the first TextBox control to your form, set the name to "txtNo", and Index to 0 in the Properties window.
In your code, call Load() to create additional controls, and you can set the Top/Left and other properties
For i = 1 To 100
Load txtNo(i)
txtNo(i).Top = txtNo(i - 1).Top + txtNo(i - 1).Height + 150
txtNo(i).Left = txtNo(i - 1).Left
txtNo(i).Text = "Textbox " & i
txtNo(i).Visible = True
Next i
If you need again to change any control property, from your list of controls, you can iterate only over your control list, instead of all controls of your Form
For i = txtNo.LBound() To txtNo.UBound()
Form1.Controls("txtNo")(i).Text = "New text " & i
Next i
I wrote a code to break links to the source excel file for my powerpoint deck, the macro works well except for 2 charts. Both the charts are on the same slide (which is not uncommon) and are line charts. The charts need to be manually updated but the data resides in a excel file only. Not sure what am I missing. This is the code that I wrote
Sub SavePPT()
Dim objPP As Object
Dim objPPFile As Object
Dim sld As Object
Dim shp As Object
Dim shp1 As Chart
Dim newshp As Shape
Dim pptChart As Object
Set objPP = CreateObject("PowerPoint.Application")
objPP.Visible = True
Set objPPFile = objPP.ActivePresentation
objPPFile.Save
Application.EnableEvents = False
For Each sld In objPPFile.Slides
For Each shp In sld.Shapes
If shp.HasChart Then
shp.LinkFormat.BreakLink
On Error GoTo 0
End If
Next
Next
Application.EnableEvents = False
For Each sld In objPPFile.Slides
For Each shp In sld.Shapes
If shp.Type = msoLinkedOLEObject Or shp.Type = msoEmbeddedOLEObject Then
shp.LinkFormat.BreakLink
On Error GoTo 0
End If
Next
Next
objPPFile.SaveAs ("Location" _ & Format(Now(), "MM-DD-YYYY") & ".pptx")
objPPFile.Close
objPP.Quit
Set pptChart = Nothing
Set objPPFile = Nothing
Set objPP = Nothing
End Sub
The chart might be in a placeholder, in which case none of your code will act upon it. If the shape's .Type = msoPlaceholder (ie, 14), check the shape's .PlaceholderFormat.ContainedType property to see if it's a linkedOleobject or .HasChart etc.
BTW, an msoEmbeddedOLEObject won't have a .LinkFormat object to call on; I suspect you have some error handling code that's obscuring an error there. In any case, I'd limit that check to just msoLinkedOLEObject.
Thanks for you help. I realized it later that those 2 slides have a lot of text boxes on them and when I consolidate some of those textboxes the issue was resolved.
I want to print Notes-documents directly to an pdf-printer. The documents are selected in a view. I do not want to open the printer dialog form.
Using the "NotesUIView.Print"- method works in principle, however, the generated pdf-documents sometimes look not exactly like the Notes-documents (especially regarding tables).
Therefore I tried to use the "NotesUIDocument.Print" - method:
Option Public
Option Explicit
Const pdfAppName = "PDF-XChange Standard"
Dim dc As NotesDocumentCollection
Dim curDoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
...
Set dc = curDB.UnprocessedDocuments
...
Set curdoc = dc.GetFirstDocument
Call workspace.EditDocument(False,curDoc)
Set uidoc = workspace.Currentdocument
Call uidoc.Print(1,0,0,False,pdfAppName)
...
Dispite the first parameter in "uidoc.print" is set to "1" the printer dialog form opens. In the printer dialog form the printer "PDF-XChange Standard" is selected correctly. Selecting the "OK"-Button prints the document correctly.
Many thanks in advance for hints.
After I did a query in openoffice-base over a customized form I want to transfer a selected set of data into a template openoffice-calc table. I know I can access the data set in openoffice-calc via pressing the Data Source (F4) button but then I only get access over the query. The best solution would be after the database query over a form a button event is required to open a openoffice-calc table from the template and insert the data from the data set.
First go to Tools -> Macros -> Organize Macros -> LibreOffice Basic and add this code. Change the path of the template file.
Sub Copy_Record_To_Calc(oEvent)
Dim oForm
Dim templatePath As String
Dim oServiceManager As Object, oDesktop As Object
Dim oFileProperties As Object
Dim oDoc As Object, oSheet As Object, oCell As Object
Dim column As Integer
oForm = oEvent.Source.getModel().getParent()
If oForm.isAfterLast() Then
Print "Hey, you are after the last element."
Exit Sub
ElseIf oForm.isBeforeFirst() Then
Print "Hey, you are before the first element."
Exit Sub
End If
templatePath = "file:///C:/Users/JimStandard/Desktop/Untitled 2.ots"
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oFileProperties(0) = new com.sun.star.beans.PropertyValue
oFileProperties(0).Name = "AsTemplate"
oFileProperties(0).Value = True
Set oDoc = oDesktop.loadComponentFromURL( _
templatePath, "_blank", 0, Array(oFileProperties))
oSheet = oDoc.Sheets(0)
For column = 1 to 2
oCell = oSheet.getCellByPosition(column - 1, 0)
oCell.String = oForm.getString(column)
Next column
End Sub
Then in form design mode, right-click on the button and choose Control. In the Events tab, click the three dots next to Execute action. Click Macro... and find the Copy_Record_To_Calc macro that you added.
Now turn design mode off. Go to a record and click the button. It will open the Calc template and copy the first two columns of the current record into column A and B of the spreadsheet.
See also:
Section 4.2.1 of Andrew Pitonyak's Base Macros (PDF)
ResultSet documentation
This thread gives an example of using a Calc template.
I would like to be able to add the page numbers in a word document to the header.
I have found some links that display the code in visual basic, but no matter what i try, i keep getting errors. It keeps telling me the either "sections" or "headers" or "footers" is not a supported automation object.
Any help would realy be great. Thank You.
Links:
http://blogs.technet.com/b/heyscriptingguy/archive/2006/05/10/how-can-i-add-centered-page-numbers-to-the-footer-of-a-word-document.aspx
http://msdn.microsoft.com/en-us/library/office/ff194253(v=office.14).aspx
I Tried addapting the link's code with no success:
wrdDoc.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.Add
and if possible please how to allign the page number right.
Use [] instead of () for indexes
//Headers[wdHeaderFooterPrimary] = Headers[1]
//Add possible values:
//wdAlignPageNumberCenter = 1
//wdAlignPageNumberInside = 3
//wdAlignPageNumberLeft = 0
//wdAlignPageNumberOutside = 4
//wdAlignPageNumberRight =2
wrdDoc.Sections[1].Headers[1].PageNumbers.Add(1); //example with center alignment
wrdDoc.Sections[1].Headers[1].PageNumbers.Add(2); //example with right alignment