VBA Macros to open Multiple file path store in one cell - vba

Could anyone help me with a macro that can open nultiple file path store in one cell
File path are stored in Column H and I
H1 can have file file path or multiple and same for I
For Example, if 1 file path is found, it will return as below
1,C:\Users\XXXX\Desktop\work\287497196_DN.pdf
And if 2 file path are stored, separted by a comma
2,C:\Users\XXXX\Desktop\work\Order_9250_TA_0580484707_Copy_of_del._note_XXX_signed_by_cust..TIF,C:\Users\XXXX\Desktop\work\Order_9250_TA_580484707_Customer_e-Mail.EML
The numbers in the start indicates the number of files found in a cell with file path
The files can be PDF, .TIf or .EML
Please help me how can I open all file if I click on that particular cell
Would be really helpful

Not have much time to write complete code, but try using something like:
newArray() = Split(Range("H1"), ",")
For i = 1 to Ubound(newArray)
Documents.Open newArray(i)
next i
So this will split your text with file paths using comma delimiter into an array.
After that you'll loop through array (note that 1st array element is zero, so that your loop starts from 2nd element)

Related

Copy a single column from an excel file to a text file

I am using the attached Code Here and at the moment the code that I have copies all the columns to the txt file.
I have 2 columns and the column "B" needs to be copied to txt file.
In Your Code You Use
For P=1 to Lastcolumn
wsData=ActiveSheet.Cells(1,P).value
Next
I Think This Is your Problem. You Split All the cell Values and then Write it into the txt file . You just wonna try to mention that Particular row count and you will get Solution.

Check if file exists in folder or not (SSIS, SDT 2015 and SQL 2016)

I need to load multiple files into a SQL table. I have three different formats, CSV, XLSX and XLS, but I will load one type of files at a time, no combination of different file types.
First, I will check in my source folder if the file exists or not. If it exists, load it to table and move to next file. The file checking and selection process must be dynamic. I don't want to hard code the file name in a variable. When the package starts, I need the filename variable to hold the very first file present in the folder each time when I run the package.
If the file is not found in the folder, send mail alert that file doesn't exist.
For example, if I have three files in my folder,
File1.csv
File2.csv
File3.csv
I run my package and I hard code the file name variable = File1.csv in the first run. My package gets executed successfully and loads the file1 to the table and archives it to the archive folder.
When next time for each loop runs, it looks for variable filename = File1, but it's already archived, so my package will not able to process file2 from the folder. How can I do this properly?
First use a script task to check if any file is present in the folder or not.Create an integer variable and set it to 1, if file is found and to 0 if file not found. Use expression and constraint in the precedence constraint.
http://www.techbrothersit.com/2013/07/ssis-how-to-check-if-file-exists-in.html
If evaluation expression is false,connect it to a mail task,else
connect to a for each loop task.
Please refer:https://www.simple-talk.com/sql/ssis/ssis-basics-introducing-the-foreach-loop-container/ or more details.
A trick in SSIS is to create a Foreach Loop.
Create a Variable containing the path where the file resides. Example User::filepath
Create another variable to save the actual file found on the Foreach loop, example User::filename
Add the Foreach Loop from the SSIS Toolbox.
On the Foreach Loop editor, on Collection left tab select in Enumerator - Foreach File Enumerator
Click Expressions and add one for Property Directory and select in the expression the #[User::filepath]
Enter on the Folder the value of the filepath variable (this will be overridden at execution from the Expression above, this is if you filepath is changed at runtime)
On file enter something like . or *.txt or whatever filter you want to apply to the folder.
On the Variable Mappings left tab select on the Variable column the User::filename variable, the Index column will default to 0.
Then put your logic inside the Foreach Loop box.
This will only execute your logic if a file is found. You can also use this to process multiple files if they exist on the folder.
Hope this helps.
The problem with Foreach Loop Container is it will not process any task within the container but will continue outside of it.
A solution is an expression on the constraint to the next task.
enter image description here
It will check the variable length used in the Foreach Loop Container. If a file isn't present, the expression will return 0 and FALSE.
LEN(#[User::filePath]) > 0 ? TRUE:FALSE
filePath = Foreach Lop Container variable
enter image description here

Looking to save word document as PDF with text from document as the file name

There are hundreds of contracts in .doc format that I need to save as pdf.
I am hoping to use a macro to quickly save the document as pdf using the first and last name of the person who the document was addressed to [always 2nd line of 'table' that is 1x1 -so the entire length of document]
So I think the logic would go:
Move Cursor to correct location
Select 2 words to right [i.e. first & last name]
Copy those words
Some how concatenate those words at the end of the desired filepath of a Save As statement, but before the .pdf file extension.

Text from excel cells to individual word files

I have an Excel file that looks like this:
A B
1 Title_1 Description_1
2 Title_2 Description_2
Is it possible to output each title and description to individual Word files with column A for file name of the Word file and column B to its content?
For example the macro would create a new Word file give it file name 'Title_1' and copy 'Description_1'. Then create a new Word file again give it file name 'Title_2' and copy 'Description_2'. And do this until all data from the Excel file is copied.
Thank you for your time. :)
What you want to look into is called a "Mail Merge". Use a search engine and look for "mail merge excel word 2007" (or whatever year of MS Office that you are working with). You can create an excel macro that creates instances of word, populates the word doc with whatever you want from your excel spreadsheet, save the word doc with any name you want, export to PDF, etc.
Here are some hints to start you off:
in the VBE go to tools references and add one for Microsoft Office.
Use these two lines of code to create an object:
Dim MyWord
Set MyWord = CreateObject("Word.Application")
Now you can precede any code for word with MyWord for example to add a Document in word would be Documents.Add so remotely from Excel it will be MyWord.Documents.Add
You will want to loop through your cells in excel. On each iteration of the loop populate two variables, one with the text you want in the file and one with the file name.
Then simply use MyWord to enter the results of the variable then save the file using the result of the other variable.
Post back if you get stuck but give it a go first.
This is easy form any operating system, assuming you are using windows you will use a batch script(easiest).
First use save as/export on the data ribbon to save as a CSV.
Second you will need a batch script to read the CSV and use the first value as the file name the second value as the contents. If you want it to be a doc or docx instead of txt just rename the file in the same loop or add it to the file name when you output to text.
Here is a similar post with all the resources you would need to slap together a quick batch script.
read csv file through windows batch file and create txt file

Not completed file reading

I'm trying to print the number of rows in my file training.txt but found out that my code does not read the whole file. Code goes like this:
row = 1
for line in io.lines 'training.txt' do
row = row + 1
end
print(row)
I tried changing the file with test.txt that has the same format with training.txt and file reading worked fine, reads until the end of file. So maybe the problem is with my text file? But how? It has the same format.
Text files are uploaded here for testing.
The file you uploaded training.txt is not the same format as test.txt, it does not have newline characters that indicate the EOL (End of Line). Try opening it in notepad to see the difference.