How to open a .PDF file with wild card option via excel macro
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
add a comment |
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
stackoverflow.com/q/10380312/2727437
– Marcucciboy2
Nov 15 '18 at 5:18
add a comment |
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
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
excel vba excel-vba pdf
asked Nov 15 '18 at 3:50
Nilusha M.Nilusha M.
328
328
stackoverflow.com/q/10380312/2727437
– Marcucciboy2
Nov 15 '18 at 5:18
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
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
add a comment |
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
answered Nov 15 '18 at 8:25
BigBenBigBen
6,3172618
6,3172618
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
edited Nov 15 '18 at 5:19
Marcucciboy2
2,38321022
2,38321022
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
stackoverflow.com/q/10380312/2727437
– Marcucciboy2
Nov 15 '18 at 5:18