Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2014, 12:24 AM
elmnas elmnas is offline Copy Files to a directory Windows 7 64bit Copy Files to a directory Office 2010 64bit
Novice
Copy Files to a directory
 
Join Date: Jul 2014
Posts: 6
elmnas is on a distinguished road
Default Copy Files to a directory

Hello Everyone,





I wonder if there is a way to do following.

if I am open a word document from a directory,
how do I make a word macro that look at the same directory
(get the location, the best if the macro doesn't save the word document I have opened if that is necessary to get the location)

copying two .pdf files
navigates one level up creates a folder and put the .pdf files there

Thank you in advance.

All MSofficeForum Members,
Reply With Quote
  #2  
Old 07-10-2014, 01:07 AM
macropod's Avatar
macropod macropod is offline Copy Files to a directory Windows 7 32bit Copy Files to a directory Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

ActiveDocument.Path will return the current document's folder name. To go up one level, simply strip off the last folder name from that. For example:
Code:
Sub Demo()
Dim StrOldPath As String, StrNewPath As String
StrOldPath = ActiveDocument.Path
StrNewPath = Left(StrOldPath, InStrRev(StrOldPath, "\"))
StrOldPath = StrOldPath & "\"
MsgBox StrOldPath & vbCr & StrNewPath
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-10-2014, 01:11 AM
macropod's Avatar
macropod macropod is offline Copy Files to a directory Windows 7 32bit Copy Files to a directory Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: http://www.vbaexpress.com/forum/show...ctive-location
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 07-10-2014, 01:12 AM
elmnas elmnas is offline Copy Files to a directory Windows 7 64bit Copy Files to a directory Office 2010 64bit
Novice
Copy Files to a directory
 
Join Date: Jul 2014
Posts: 6
elmnas is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
ActiveDocument.Path will return the current document's folder name. To go up one level, simply strip off the last folder name from that. For example:
Code:
Sub Demo()
Dim StrOldPath As String, StrNewPath As String
StrOldPath = ActiveDocument.Path
StrNewPath = Left(StrOldPath, InStrRev(StrOldPath, "\"))
StrOldPath = StrOldPath & "\"
MsgBox StrOldPath & vbCr & StrNewPath
End Sub


I am not so familiar with VBA, but this code flawly,

how do I make the last steps in my thread
copy the .pdf and create folder?

Thank you so much in advance sir
Reply With Quote
  #5  
Old 07-10-2014, 01:16 AM
macropod's Avatar
macropod macropod is offline Copy Files to a directory Windows 7 32bit Copy Files to a directory Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Create what folder? I also have no idea what particular two PDF files you're referring to.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 07-10-2014, 01:18 AM
elmnas elmnas is offline Copy Files to a directory Windows 7 64bit Copy Files to a directory Office 2010 64bit
Novice
Copy Files to a directory
 
Join Date: Jul 2014
Posts: 6
elmnas is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Create what folder? I also have no idea what particular two PDF files you're referring to.
the macro need to copy two pdf files, the pdfs have always different names on each job. so if we could use wildcards and .pdf to grab them. (always just 2 pdfs in the active folder path too)


then need the macro to create a folder one level up from active part called "translation to"
and put the pdfs there.

for example:

I open source.doc
at C:/jobs/341423/source/source.doc

"in C:/jobs/341423/source/" there are

2 pdfs.
2 word files.

"I need to create a folder in "C:/jobs/341423/translation to"

and put the two pdfs from "C:/jobs/341423/source/" to "C:/jobs/341423/translation to"
Reply With Quote
  #7  
Old 07-10-2014, 02:01 AM
elmnas elmnas is offline Copy Files to a directory Windows 7 64bit Copy Files to a directory Office 2010 64bit
Novice
Copy Files to a directory
 
Join Date: Jul 2014
Posts: 6
elmnas is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Create what folder? I also have no idea what particular two PDF files you're referring to.

I am almost finished

need to create folder tho


Sub Test1()
'
' Test1 Makro
'

Dim StrOldPath As String, StrNewPath As String
StrOldPath = ActiveDocument.Path
StrNewPath = Left(StrOldPath, InStrRev(StrOldPath, "\"))
StrOldPath = StrOldPath & "\"


FileExt = "*.pdf*" '<< Change
'You can use *.* for all files or *.doc for Word files

If Right(StrOldPath, 1) <> "\" Then
StrOldPath = StrOldPath & "\"
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(StrOldPath) = False Then
MsgBox StrOldPath & " doesn't exist"
Exit Sub
End If

If FSO.FolderExists(StrNewPath) = False Then
MsgBox ToPath & " doesn't exist"
Exit Sub
End If

FSO.CopyFile Source:=StrOldPath & FileExt, Destination:=StrNewPath
MsgBox "You can find the files from " & StrOldPath & " in " & StrNewPath


End Sub
Reply With Quote
  #8  
Old 07-10-2014, 06:22 AM
macropod's Avatar
macropod macropod is offline Copy Files to a directory Windows 7 32bit Copy Files to a directory Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Dim StrOldPath As String, StrNewPath As String, strFile
StrOldPath = ActiveDocument.Path
StrNewPath = Left(StrOldPath, InStrRev(StrOldPath, "\"))
StrOldPath = StrOldPath & "\"
StrNewPath = StrNewPath & "translation to\"
If Dir(StrNewPath, vbDirectory) = "" Then
  MkDir StrNewPath
End If
strFile = Dir(StrOldPath & "*.PDF", vbNormal)
While strFile <> ""
  FileCopy StrOldPath & strFile, StrNewPath & strFile
  Kill StrOldPath & strFile
  strFile = Dir()
Wend
End Sub
To merely copy the files, delete 'Kill StrOldPath & strFile'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 07-11-2014, 12:07 AM
elmnas elmnas is offline Copy Files to a directory Windows 7 64bit Copy Files to a directory Office 2010 64bit
Novice
Copy Files to a directory
 
Join Date: Jul 2014
Posts: 6
elmnas is on a distinguished road
Default

Thank you sir my problem is solved you are one of the first people on all VBA forums I hang on,


that actually can solve my problem good work man!
Reply With Quote
Reply

Tags
copy files, move files, pdf



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy, sync files across 2 folders 1 pc spgprivate Office 0 06-20-2013 08:41 AM
How to copy linked Excel and Word files and retain links ashleynpeters1 Word 1 05-30-2013 02:25 PM
Alphabetize Directory Moira Windows 1 05-16-2013 03:20 PM
Active Directory ababc Misc 0 09-19-2006 06:18 AM
Active Directory nukkumatti Misc 0 11-16-2005 08:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft