In MS-Powerpoint 2010, insert an image which has a name ABC.gif.
When I use the code to read the .pptx file, I can't get the original image's file name which should be ABC.gif, but instead I get "Image1.gif.
Can someone tell me how can I get the original image's fileName ABC.gif.
Using Microsoft.Office.Interop.PowerPoint, for the code operate.
Not sure if you are using VB.Net or C# so I will explain it using VBA code. You can easily adapt it to your code.
To get the filename you have to ensure that you do not just "Insert" the image but "Insert And Link" See the below screenshot.
Remember MS-PP will rename the picture to "Picture 1, Picture 2" etc in this case as well but then you can always use LinkFormat.SourceFullName to get the full Filename + Path. And once you have that, you can easily retrieve the file name.
See this example
Option Explicit
Sub Sample()
Dim img As Shape
For Each img In ActivePresentation.Slides(1).Shapes
'~~> Type is 11 when you insert and link an image
If img.Type = msoLinkedPicture Then
Debug.Print img.LinkFormat.SourceFullName
Debug.Print img.Name
End If
Next
End Sub
SCREENSHOT
Related
I have about 50 icon images (.ico) on an Access form, however I don't have them stored on a disk. I'd like to export them from Access onto a disk location.
I tried the suggested solution on this thread:
Access - Export images from Image controls in forms
I couldn't open the resulting file, probably because my images are (.ico) rather than (.png)
EDIT: I'm able to copy the icons into paint, save them as pngs, then use an online converter to convert them to icons. Pretty time consuming but it works.
You can use this code blow.
It will save the content of all image controls of the provided form to files in the same folder.
Beware that some image controls contain 'strange' binary formats which maybe can't be displayed properly by every tool.
Also you would have to take care to assign a correct file extension after exporting yourself.
Place the code in a new module, then open the form in design view and call it like this: SaveAllImageControls Forms("MyForm")
Public Sub SaveAllImageControls(ByRef sourceForm As Form)
Dim item As control
For Each item In sourceForm.Controls: Do
If item.ControlType <> acImage Then Exit Do
If IsNull(item.PictureData) Then Exit Do
Dim bArray() As Byte
bArray = item.PictureData
Dim filename As String
filename = Application.CurrentDb.Name & "-" & sourceForm.Name & "-" & item.Name & ".binary"
Dim fileNumber As Integer
fileNumber = FreeFile
Open filename For Binary As fileNumber
Put fileNumber, , bArray
Close fileNumber
Loop While False: Next item
End Sub
The simplest solution is probably to export all the ico files and then process them with ImageMagick. You can run something like
convert image.ico image.png
either as part of the code you linked to or as a plain one time call in a command prompt.
I have a word document with many images in it and I wish to be able to select a file path (in which the new images are located and numbered i.e. 1 to 100) to then replace the existing images with the new images.
I have read a few posts of others retrieving the properties of existing inlineshapes to achieve this, but I have also read people succeeding with the following method which seems much simpler (I just haven't been able to get the code working fully yet). Currently the code will run and replace the last image perfectly fine, but then stops with error '438' - Object doesn't support this property or method when it tries to replace the second last image.
The code is as follows:
Sub Replace_images()
Dim rg As Word.Range
Dim i As Long
Dim doc As Word.Document
Dim path As String
'Ensure pictures are numbered with no leading zeros (in folder) & are .jpg
path = "C:\filepathtopictures\"
Set doc = ActiveDocument
For i = doc.InlineShapes.Count To 1 Step -1
Set rg = doc.InlineShapes(i).Range
doc.InlineShapes(i).Delete
rg = doc.InlineShapes.AddPicture(path & i & ".jpg", False, True, rg)
Next i
End Sub
I don't understand how the using the addpicture doesn't work for the next image when nothing has change from the last image. If someone could please explain why it doesn't work or tell me what needs to be changed that would be great!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
You can open PDFs in text editors to see the structure of how the PDF is written.
Using VBA I have opened a PDF as a text file and go to extract the text and save it as a string variable in VBA. I want to look through this text to find a specific element; a polyline (called sTreamTrain) and get the vertices of the polyline by using the InStr function.
When i add more vertices to the polyline I cannot seem to extract the text string of the pdf. I get the error 'Run time error 62' which I do not understand what it means or what about the PDF has changed to now have this error.
Attached (via the link) is a PDF that I can read (Document 15) and a PDF I cannot read (Document 16). I have checked in excel so see that the vertices are present in both files. Also there is a copy of my VBA script as a notepad document and also my excel file (but it is difficult to find in my excel file - the script is "Module 6" function called "CoordExtractor_TestBuild01()")
Link:
https://drive.google.com/open?id=1zOhwnFWZZfy9bTAxKiQFSl7qiQLlYIJV
Code snippet of the text extraction process below to reproduce the problem (given an applicable pdf is used):
Sub CoordExtractor_TestBuild01()
'Opening the PDF and getting the coordinates
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
'File Path of Text File
FilePath = "C:\Users\KAllan\Documents\WorkingInformation\sTreamTrain\Document16 - Original.pdf"
'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile
'Open the text file in a Read State
Open FilePath For Input As TextFile
'Store file content inside a variable
Dim Temp As Long
Temp = LOF(TextFile)
FileContent = Input(LOF(TextFile), TextFile)
'Clost Text File
Close TextFile
End Sub
I would like someone to let me know what runtime error 62 is in this context and propose any workflows to get around it in future. Also, I would like to know whether there certain characters you cannot store as strings? - Perhaps these are included when I increase the number of vertices past a certain number.
Also I would prefer to keep the scrips quite simple and not use external libraries because I want to share the script when it is done so others can use it thus its simpler if it works without extra dependencies etc, however, any and all advice welcome since this is only the first half of this project.
Thank you very much.
According to the MSDN documentation, this error is caused by the file containing
...blank spaces or extra returns at the end of the file or the syntax
is not correct.
Since your code works sometimes on documents with very similar names and content to documents where it doesn't work, we can rule out syntax errors in this case.
You can clean up the file contents before processing it any further by replacing the code at the top of your macro with the one below. With this I can read and extract information from your Document16.pdf:
Sub CoordExtractor_TestBuild01()
'Purpose to link together the extracting real PDF information and outputting the results onto a spreadsheet
'########################################################################################
'Opening the PDF and getting the coordinates
Dim n As Long
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
'File Path of Text File
FilePath = "C:\TEST\Document16.pdf" ' change path
'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile
'Open the text file in a Read State
Open FilePath For Input As TextFile
Dim strTextLine As String
Dim vItem As Variant
Line Input #1, strTextLine
vItem = Split(strTextLine, Chr(10))
' clean file of garbage information line by line
For n = LBound(vItem) To UBound(vItem)
' insert appropriate conditions here - in this case if the string "<<" is present
If InStr(1, vItem(n), "<<") > 0 Then
If FileContent = vbNullString Then
FileContent = vItem(n)
Else
FileContent = FileContent & Chr(10) & vItem(n)
End If
End If
Next n
'Clost Text File
Close TextFile
' insert the rest of the code here
I have a Powerpoint with images inserted using Link and Insert.
I need to change the file names that they link to.
I haven't got access to the source folder.
Therefore need to make the change to via VBA.
I can change the folder location, just not the name of the file.
All that needs changing is the 'Doncaster' to 'London'
X:\Central\Buildings\District\Images\Forecast_Doncaster.png
X:\Central\Buildings\District\Images\History_Doncaster.png
X:\Central\Buildings\District\Images\Current_Doncaster.png
I tried but it doesn't work
submarket ="London"
sh.TextFrame.TextRange = Replace(sh.TextFrame.TextRange, "Doncaster", submarket
Can anyone please help?
The code you posted will change the text in the shape but not the link to a picture. For that you need something more like this:
Sub Test()
Call EditLink(ActiveWindow.Selection.ShapeRange(1), ".png", ".jpg")
End Sub
Sub EditLink(oSh As Shape, strOriginalText As String, strNewText As String)
With oSh.LinkFormat
.SourceFullName = Replace(.SourceFullName, strOriginalText, strNewText)
End With
End Sub
In this example, I'm changing the link to point to a JPG of the same name as the original file which is a PNG. Modify as needed to change directory names for your project
A slight amendment to Steve's answer which I used and it worked! thank you.
ActiveWindow.View.GotoSlide s.SlideIndex
Call EditLink(sh, "Doncaster", "London")
I've been searching around on Google to find a better way to show images in Access without actually inserting the image into the database.
I found this article 'http://support.microsoft.com/kb/285820' via this thread 'Is there a way to get ms-access to display images from external files' which goes into great detail on how to set paths to pictures through folders/files, and it works great, for a 'set' picture. However, I want a different picture to display when I switch to a different record.
Here is the code from the article:
Option Compare Database
Option Explicit
Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No image name specified."
Else
If InStr(1, strImagePath, "\") = 0 Then
' Path is relative
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = "Image found and displayed."
End If
End With
Exit_DisplayImage:
DisplayImage = strResult
Exit Function
Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Can't find image in the specified name."
Resume Exit_DisplayImage:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function
I have a feeling that I need to place a line of code that states something like, show image where Image.ID = "ID", but I can't figure out where to put it without getting errors. Am I over-looking something perhaps, or am I approaching this the wrong way? I just don't want to clutter my database, memory-wise, with .bmp images, but I feel like I am going to have to.
SOLVED: A much easier solution is as Gord Thompson has described below in the comments. And from my own experience, using this method for .bmp images leaves the picture distorted and out of contrast. I tested the image for .jpg and it worked perfectly! I hope this helps others who are having trouble with similar problems finds this post helpful.
The Microsoft Support article you cited applies to Access 2003. In Access 2010 (and later) there is a much simpler way to do it. All you need to do is place an Image control on the form and bind it to the field in your table that contains the path to the image file.
For example, with an [Employees] table like this
EmployeeID FirstName LastName PhotoPath
---------- --------- -------- ---------------------------------
1 Gord Thompson C:\Users\Public\Pictures\Gord.jpg
2 Hank Kingsley C:\Users\Public\Pictures\Hank.png
you could use an Image control whose Control Source is the [PhotoPath] field ...
... and the image will automatically be retrieved from the file specified
No VBA required.
Note also that the image files do not have to be .bmp files.
Added by an anonymous user:
For users of the Microsoft Office 365 version of MS Access (c. 2020), here is what you may need to know in order to get this terrific solution to work:
The [PhotoPath] field in its data table needs to be "Long Text" data type, if using long paths or long file names. The [PhotoPath] field format "Is Hyperlink" may need to be set to "No." I was getting additional, unwanted coding from Access on my text inputs. The [Image3] control may need to specify "Linked" rather than "Embedded."