antonismouf
Board Regular
- Joined
- Aug 18, 2015
- Messages
- 64
So, I am using a code to open a word file and paste there some data from excel and save it, but I have a problem.
The file is in dropbox and using it from different pc it exists is a different directory:
1)C:\Users\user\Dropbox
2)C:\Users\pc\Dropbox
I cannot change the folder name because it conflicts with so many different things and creates issues with other programs.
So I need a code to try and open the file in one location and if it is not there open it from the second one (and also save in the other one). Below is my code:
The file is in dropbox and using it from different pc it exists is a different directory:
1)C:\Users\user\Dropbox
2)C:\Users\pc\Dropbox
I cannot change the folder name because it conflicts with so many different things and creates issues with other programs.
So I need a code to try and open the file in one location and if it is not there open it from the second one (and also save in the other one). Below is my code:
Code:
Sub WordUp()
Dim WdObj As Object, fname As String
fname = Sheets(2).[b1].Value
If fname <> "" Then 'make sure fname is not blank
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = True
finalrow = Sheets("Prosfora").Range("A9999").End(xlUp).Row
Sheets("Prosfora").Range("A2:A" & finalrow).Copy
WdObj.Documents.Open Filename:="C:\Users\User\Dropbox\ÐÑÏÃÑÁÌÌÁÔÁ\prosfora template1.docx"
With WdObj
.ChangeFileOpenDirectory "C:\Users\User\Dropbox\ÐÑÏÃÑÁÌÌÁÔÁ" 'save Dir
.ActiveDocument.SaveAs Filename:="Ðñïóöïñá " & fname & ".doc"
End With
WdObj.Selection.PasteSpecial Link:=False ', DataType:=wdPasteText , Placement:=wdInLine, DisplayAsIcon:=False
Application.CutCopyMode = False
WdObj.ActiveDocument.Save
Else:
MsgBox ("ÐñïóèÝóôå ¼íïìá ÐåëÜôç")
End If
Set WdObj = Nothing
End Sub