Hyperlink Path problem(%5b %5d)

brkkrkmz112

New Member
Joined
Oct 24, 2016
Messages
43
Hello,

I've done some searching but can't find anything works. I need to use path of hyperlinks but some of them contains box brackets and it is shown like %5b %5d etc. Hyperlinks are working perfectly but for the other macro I need to take path information from hyperlinks and the ones containes box brackets cause error which is path could not found.

Is there anything that I can do. I sharing the code below. Thank you.

VBA Code:
Sub burak()

Dim outapp As Object
Dim foldername As String
Dim Msg As Object
Dim foldername1 As String, foldername2 As String
Dim dosya As Object
Dim wordapp As Object

Dim worddoc As Object

Application.ScreenUpdating = False
Dim sNewDocName As String

Set wordapp = CreateObject("Word.Application")

Set outapp = CreateObject("Outlook.Application")

foldername1 = Selection.Hyperlinks(1).Address
foldername = ThisWorkbook.Path + "\" + foldername1
foldername2 = Right(foldername1, Len(foldername1) - 4)
foldername2 = Left(foldername2, Len(foldername2) - 4)

Set Msg = outapp.Session.OpenSharedItem(foldername)

Msg.Display

Msg.SaveAs "C:\Users\Administrator\Desktop\Mail1\REFPDF\" & foldername2 & ".doc", olDoc

Set worddoc = wordapp.Documents.Open(Filename:="C:\Users\Administrator\Desktop\Mail1\REFPDF\" & foldername2 & ".doc")

worddoc.ExportAsFixedFormat OutputFileName:= _
            "C:\Users\Administrator\Desktop\Mail1\REFPDF\" & foldername2 & ".pdf", ExportFormat:= _
            wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
            wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=0, To:=0, _
            Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False

ActiveSheet.Hyperlinks.Add Range("r" & Selection.Row), "C:\Users\Administrator\Desktop\Mail1\REFPDF\" & foldername2 & ".pdf", TextToDisplay:="GAP's evaluation"

     Msg.Close olDiscard
     
     Application.ScreenUpdating = True
     

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I handled it myself, for those who may have encountered the same problem, in order to obtain parenthesis as its original version, just adding replace function for the "%5b %5d" and using CHR(91) and CHR(93).

VBA Code:
foldername1 = Selection.Hyperlinks(1).Address
foldername1 = Replace(foldername1, "%5b", Chr(91))
foldername1 = Replace(foldername1, "%5d", Chr(93))

foldername = ThisWorkbook.Path + "\" + foldername1

foldername2 = Right(foldername1, Len(foldername1) - 4)
foldername2 = Left(foldername2, Len(foldername2) - 4)
foldername2 = Replace(foldername2, "%5b", Chr(91))
foldername2 = Replace(foldername2, "%5d", Chr(93))
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top