VBA to Star Basic (OpenOffice), struggling - vba

I have this task to convert recenntly written VBA code to OpenOffice version. I tried to launch it from OpenOffice, but it doesn't work (mostly "unsatisfied query..." error. I am now stuck on Open File Dialog, I can either use VBA compatible open file dialog as mine looks now like that (giving error):
FileToOpen = Application.GetOpenFilename("Please choose a file to import", "Excel Files *.dbf (*.dbf)")
I can also use OpenOffice file dialog box, but couldn't find any information on this.
Thanks in advance

I'm confused on what you're asking, but if you're having trouble creating a file dialog box, this is VBA code that will do it for you. I think this is what you're asking, but I could be wrong.
Private Sub cmdFileDialog_Click()
' This requires a reference to the Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Clear the list box contents.
Me.FileList.Value = ""
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Change allowmultiselect to true if you want them to be able to select multiple files
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Select One or More Files"
' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
' Loop through each file that is selected and then add it to the list box.
For Each varFile In .SelectedItems
Me.FileList.Value = varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub

Related

Save Picture in an MS Access 2016 Form Image Control to folder

This is my first time posting and before I get into my question I just want to say how much I appreciate all the time and effort everyone puts into solving these problems.
I'm working on setting up a simple project management system which uses both MS Access and Excel. Through various forms in Access a user can set up a new project with name, address, logo etc. For the logo a user can double click on an image control box and choose a jpeg from any folder they choose.
My problem is with saving the logo. When the user clicks on the Save button, I would like to save the picture into a specific folder, not the one the user choose from.
This code, which works as expected, gives me the file path of where the user chose the picture from and displays the picture.
Private Sub CompLogo_DblClick(Cancel As Integer)
Dim sFile As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Choose Logo"
.Filters.Clear
.Filters.Add "JPEG", "*.jpg"
If .Show = -1 Then
sFile = .SelectedItems(1)
End If
End With
If sFile <> "" Then
Me.CompLogo.Picture = sFile
End If
End Sub
I know I can save the path as text in an Access table...
Sub SaveNewProject()
Set rst = CurrentDb.OpenRecordset("ProjectsTbl", dbOpenTable)
rst.AddNew
rst!Logo = LogoFilePath
rst.Update
rst.Close
Set rst = Nothing
End Sub
... but I need the actual jpeg to be saved in the specific folder so it can be used later in the Excel side of the program.
Any help you can give is much appreciated.

Open a Word 2013 legacy Open dialog in a specific folder

I have a simple Word macro that shows the legacy Open dialog.
Sub LegacyOpen()
DoEvents
Dialogs(wdDialogFileOpen).Show
End Sub
I’m now trying to get it to open in a specific folder.
"C:\Users\Paul Schroeter\Documents\Microsoft Word Documents".
After about an hour I have not found an macro argument or example of how to get it to do what I want it to do.
If you wonder why I need to do this, it’s because every time I use “Search documents” in the legacy Open dialog, it resets the Open dialog path to "C:\Users\Paul Schroeter\Documents", which is driving me insane, because I then have to change it back to the folder where I actually keep my Word documents.
A number of the built-in Word dialog boxes have "dialog box arguments" corresponding to some of the controls/settings in the dialog box. A list can be found here. These are not part of the Intellisense and are late-bound into the object model. The developer needs to know they exist and how to look them up and use them.
One of these built-in arguments is to set/read the file full name from the File/Open dialog box. In VBA the arguments are usually used in a With block. Putting the argument before the Show or Display method executes the setting before the dialog box is shown to the user. If it's placed after the method, then it's used to read the user's choice.
Sub WordFileOpen()
Dim dlg As Word.Dialog
Dim sPath As String
Set dlg = Application.Dialogs(wdDialogFileOpen)
sPath = "C:\Users\Paul Schroeter\Documents\Microsoft Word Documents"
With dlg
.Name = sPath
.Show
End With
End Sub
If you consider something different than Dialogs collection you could use FileDialogs property. Here is working example:
Sub OtherWindowType()
Dim FD As FileDialog
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
.AllowMultiSelect = False
.InitialFileName = "c:\" '...your path here
.Show
End With
'if you want to open the file...
If FD.SelectedItems.Count > 0 Then
Documents.Open FD.SelectedItems(1)
End If
End Sub

Access VBA - Dialog Box. Looking for an specific file

Now I have this code in order to open a dialog box to search for a concrete type of file, a .txt called memory: memory.txt
So:
Dim S As String
S = OpenCommDlg("C:\memory.txt")
If IsNull(S) Or S = "" Then Exit Sub
Unfortunately, this opens a dialog box in C:\, of course, but looking for image type archives, which is absolutely not what I'm looking for. You can see this at the right side of the attached image:
Anyone knows how to modify this code in order to find the kind of archive we are looking for, and it's name...
You can use the FileDialog method. This will save the full file path to your s string, and you can add multiple filters to filter by file type.
Dim s As String
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Filters.Add "All Files", "*.*"
If .Show Then s = .SelectedItems(1)
End With
Debug.Print s
If you want to automatically fill in the inputbox with your filename, then you can just add this line to the with statement:
.InitialFileName = "C:\memory.txt"

Open Windows level fileopen dialog via vba

When I open the standard fileopen dialog using VBA (Word)
e.g., Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
I get what I ask for, but it's not what I want. I am defaulted to opening the selected file in the parent program. (If in Word, and displaying Excel files, the selected Excel file will open in Word, not the program associated with the .xls extension; if displaying PDF, the selected file will open in Word, etc.).
How can I get a Window's level (as opposed to application level) dialog to open so that when I click a document with a non-Word extension, the proper program associated with the file extension will be called. (I know that I can always right click on the file and click 'Open With . . . ', but I don't want to have to teach this to my staff if I can avoid it.)
Private Sub Tester()
Dim fd As FileDialog, sh As Object
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All files", "*.*"
If .Show = -1 Then
Set sh = CreateObject("Shell.Application")
sh.Open .SelectedItems(1)
End If
End With
End Sub

Word VBA Save As Dialog with custom filter?

Is there a way (code) for "Save As" dialog in Word VBA with customer filters? For example: ".ttt"
I think you probably want to use the Application.FileDialog as this allows custom file filters. As KazJaw points out you can't save a Photoshop file in Word so I assume its to allow some other manipulation of a psd file.
The following shows you how to use it (see http://msdn.microsoft.com/en-us/library/aa219843%28office.11%29.aspx). Note this will allow the user to select multiple files though.
Sub CustomFilter()
'Declare a variable for the FileDialog object and one for the selectedItems
Dim fd As FileDialog, vSelectedItem As Variant
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'With the FileDialog
With fd
.Filters.Clear 'Clear current filters
.Filters.Add "Photoshop Files", "*.psd", 1 'Add a filter that has Photoshop Files.
If .Show = -1 Then
'Step through each String in the FileDialogSelectedItems collection.
For Each vSelectedItem In .SelectedItems
'Do whatever you want here
Next vSelectedItem
Else
'The user pressed Cancel.
End If
End With
Set fd = Nothing
End Sub