How to open a .PDF file with wild card option via excel macro












0















Since I am very new to the excel macro I am trying to develop a code which is able to open the PDF file.But There are some PDF files in my system which are generated by another system therefore those files names change day by day and some figures are included too.



As an example,"Process Report 151120183569844" like this.These figures change everyday.I tried it with adding WILDCARD option but it doesn't work.How do I open this PDF with only a part of the file name?



     Sub Open_PDF()
Dim pdfPath As String
pdfPath ="D:ReportsProcess Report*" & ".pdf" 'I used wildcard instead "Process Report 151120183569844"'
Call OpenAnyFile(pdfPath)
End Sub

Function openAnyFile(strPath As String)
Set objShell = CreateObject("Shell.Application")
objShell.Open(strPath)
End Function









share|improve this question























  • stackoverflow.com/q/10380312/2727437

    – Marcucciboy2
    Nov 15 '18 at 5:18


















0















Since I am very new to the excel macro I am trying to develop a code which is able to open the PDF file.But There are some PDF files in my system which are generated by another system therefore those files names change day by day and some figures are included too.



As an example,"Process Report 151120183569844" like this.These figures change everyday.I tried it with adding WILDCARD option but it doesn't work.How do I open this PDF with only a part of the file name?



     Sub Open_PDF()
Dim pdfPath As String
pdfPath ="D:ReportsProcess Report*" & ".pdf" 'I used wildcard instead "Process Report 151120183569844"'
Call OpenAnyFile(pdfPath)
End Sub

Function openAnyFile(strPath As String)
Set objShell = CreateObject("Shell.Application")
objShell.Open(strPath)
End Function









share|improve this question























  • stackoverflow.com/q/10380312/2727437

    – Marcucciboy2
    Nov 15 '18 at 5:18
















0












0








0


1






Since I am very new to the excel macro I am trying to develop a code which is able to open the PDF file.But There are some PDF files in my system which are generated by another system therefore those files names change day by day and some figures are included too.



As an example,"Process Report 151120183569844" like this.These figures change everyday.I tried it with adding WILDCARD option but it doesn't work.How do I open this PDF with only a part of the file name?



     Sub Open_PDF()
Dim pdfPath As String
pdfPath ="D:ReportsProcess Report*" & ".pdf" 'I used wildcard instead "Process Report 151120183569844"'
Call OpenAnyFile(pdfPath)
End Sub

Function openAnyFile(strPath As String)
Set objShell = CreateObject("Shell.Application")
objShell.Open(strPath)
End Function









share|improve this question














Since I am very new to the excel macro I am trying to develop a code which is able to open the PDF file.But There are some PDF files in my system which are generated by another system therefore those files names change day by day and some figures are included too.



As an example,"Process Report 151120183569844" like this.These figures change everyday.I tried it with adding WILDCARD option but it doesn't work.How do I open this PDF with only a part of the file name?



     Sub Open_PDF()
Dim pdfPath As String
pdfPath ="D:ReportsProcess Report*" & ".pdf" 'I used wildcard instead "Process Report 151120183569844"'
Call OpenAnyFile(pdfPath)
End Sub

Function openAnyFile(strPath As String)
Set objShell = CreateObject("Shell.Application")
objShell.Open(strPath)
End Function






excel vba excel-vba pdf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 3:50









Nilusha M.Nilusha M.

306




306













  • stackoverflow.com/q/10380312/2727437

    – Marcucciboy2
    Nov 15 '18 at 5:18





















  • stackoverflow.com/q/10380312/2727437

    – Marcucciboy2
    Nov 15 '18 at 5:18



















stackoverflow.com/q/10380312/2727437

– Marcucciboy2
Nov 15 '18 at 5:18







stackoverflow.com/q/10380312/2727437

– Marcucciboy2
Nov 15 '18 at 5:18














2 Answers
2






active

oldest

votes


















1














As pointed out in another answer, the Dir function with a wildcard should do the trick.



Here's an example using the original openAnyFile function.



Sub Open_PDF()
Dim filePath As String, fileName As String

filePath = "D:Reports"
fileName = Dir(filePath & "Process Report*.pdf")

If fileName <> "" Then
openAnyFile filePath & fileName
End If
End Sub

Function openAnyFile(strPath As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.Open (strPath)
End Function





share|improve this answer
























  • Yes,it got worked.I really appreciate your assistance.

    – Nilusha M.
    Nov 15 '18 at 10:16











  • Great! Glad to help.

    – BigBen
    Nov 15 '18 at 10:16



















1














You cannot open a file using a wildcard - it's just common sense, what if more than one file was matching your criteria - which one would you want to program to open? You have to specify the exact file name to open it.



if there is just one file in the target directory, you can use something like the following code to open it, regardless of its name:



sFound = Dir(ActiveWorkbook.Path & "Process Report*.xlsm") 

If sFound <> "" Then
Workbooks.Open filename:= ActiveWorkbook.Path & "" & sFound
End If





share|improve this answer


























  • I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

    – Nilusha M.
    Nov 15 '18 at 4:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312167%2fhow-to-open-a-pdf-file-with-wild-card-option-via-excel-macro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














As pointed out in another answer, the Dir function with a wildcard should do the trick.



Here's an example using the original openAnyFile function.



Sub Open_PDF()
Dim filePath As String, fileName As String

filePath = "D:Reports"
fileName = Dir(filePath & "Process Report*.pdf")

If fileName <> "" Then
openAnyFile filePath & fileName
End If
End Sub

Function openAnyFile(strPath As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.Open (strPath)
End Function





share|improve this answer
























  • Yes,it got worked.I really appreciate your assistance.

    – Nilusha M.
    Nov 15 '18 at 10:16











  • Great! Glad to help.

    – BigBen
    Nov 15 '18 at 10:16
















1














As pointed out in another answer, the Dir function with a wildcard should do the trick.



Here's an example using the original openAnyFile function.



Sub Open_PDF()
Dim filePath As String, fileName As String

filePath = "D:Reports"
fileName = Dir(filePath & "Process Report*.pdf")

If fileName <> "" Then
openAnyFile filePath & fileName
End If
End Sub

Function openAnyFile(strPath As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.Open (strPath)
End Function





share|improve this answer
























  • Yes,it got worked.I really appreciate your assistance.

    – Nilusha M.
    Nov 15 '18 at 10:16











  • Great! Glad to help.

    – BigBen
    Nov 15 '18 at 10:16














1












1








1







As pointed out in another answer, the Dir function with a wildcard should do the trick.



Here's an example using the original openAnyFile function.



Sub Open_PDF()
Dim filePath As String, fileName As String

filePath = "D:Reports"
fileName = Dir(filePath & "Process Report*.pdf")

If fileName <> "" Then
openAnyFile filePath & fileName
End If
End Sub

Function openAnyFile(strPath As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.Open (strPath)
End Function





share|improve this answer













As pointed out in another answer, the Dir function with a wildcard should do the trick.



Here's an example using the original openAnyFile function.



Sub Open_PDF()
Dim filePath As String, fileName As String

filePath = "D:Reports"
fileName = Dir(filePath & "Process Report*.pdf")

If fileName <> "" Then
openAnyFile filePath & fileName
End If
End Sub

Function openAnyFile(strPath As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.Open (strPath)
End Function






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 8:25









BigBenBigBen

6,0592518




6,0592518













  • Yes,it got worked.I really appreciate your assistance.

    – Nilusha M.
    Nov 15 '18 at 10:16











  • Great! Glad to help.

    – BigBen
    Nov 15 '18 at 10:16



















  • Yes,it got worked.I really appreciate your assistance.

    – Nilusha M.
    Nov 15 '18 at 10:16











  • Great! Glad to help.

    – BigBen
    Nov 15 '18 at 10:16

















Yes,it got worked.I really appreciate your assistance.

– Nilusha M.
Nov 15 '18 at 10:16





Yes,it got worked.I really appreciate your assistance.

– Nilusha M.
Nov 15 '18 at 10:16













Great! Glad to help.

– BigBen
Nov 15 '18 at 10:16





Great! Glad to help.

– BigBen
Nov 15 '18 at 10:16













1














You cannot open a file using a wildcard - it's just common sense, what if more than one file was matching your criteria - which one would you want to program to open? You have to specify the exact file name to open it.



if there is just one file in the target directory, you can use something like the following code to open it, regardless of its name:



sFound = Dir(ActiveWorkbook.Path & "Process Report*.xlsm") 

If sFound <> "" Then
Workbooks.Open filename:= ActiveWorkbook.Path & "" & sFound
End If





share|improve this answer


























  • I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

    – Nilusha M.
    Nov 15 '18 at 4:59
















1














You cannot open a file using a wildcard - it's just common sense, what if more than one file was matching your criteria - which one would you want to program to open? You have to specify the exact file name to open it.



if there is just one file in the target directory, you can use something like the following code to open it, regardless of its name:



sFound = Dir(ActiveWorkbook.Path & "Process Report*.xlsm") 

If sFound <> "" Then
Workbooks.Open filename:= ActiveWorkbook.Path & "" & sFound
End If





share|improve this answer


























  • I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

    – Nilusha M.
    Nov 15 '18 at 4:59














1












1








1







You cannot open a file using a wildcard - it's just common sense, what if more than one file was matching your criteria - which one would you want to program to open? You have to specify the exact file name to open it.



if there is just one file in the target directory, you can use something like the following code to open it, regardless of its name:



sFound = Dir(ActiveWorkbook.Path & "Process Report*.xlsm") 

If sFound <> "" Then
Workbooks.Open filename:= ActiveWorkbook.Path & "" & sFound
End If





share|improve this answer















You cannot open a file using a wildcard - it's just common sense, what if more than one file was matching your criteria - which one would you want to program to open? You have to specify the exact file name to open it.



if there is just one file in the target directory, you can use something like the following code to open it, regardless of its name:



sFound = Dir(ActiveWorkbook.Path & "Process Report*.xlsm") 

If sFound <> "" Then
Workbooks.Open filename:= ActiveWorkbook.Path & "" & sFound
End If






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 5:19









Marcucciboy2

2,37621022




2,37621022










answered Nov 15 '18 at 4:32









Michal RosaMichal Rosa

1,3191814




1,3191814













  • I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

    – Nilusha M.
    Nov 15 '18 at 4:59



















  • I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

    – Nilusha M.
    Nov 15 '18 at 4:59

















I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

– Nilusha M.
Nov 15 '18 at 4:59





I really appreciate your answer but my problem is that it is not an excel file,it is a PDF file.If it is an excel file I know how to open through wildcard but I do not know how it associates with PDF files.

– Nilusha M.
Nov 15 '18 at 4:59


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312167%2fhow-to-open-a-pdf-file-with-wild-card-option-via-excel-macro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()