|
View Full Version : opening a word document from project
Steff 06-28-2007, 07:10 PM Next Question on this journey...
I am trying to open a document from a master document list and then save it
using the name that the user inputs. Here is my code
Private Sub CommandButton1_Click()
'Create A Package
Dim WordApp As Word.Application
Dim strPacName As String
Dim Count As Long
Dim NewPac As Long
strPacName = InputBox("Equipment Name", "Package Creation", , , ,
"c:\Windows\Help\Procedure Help.chm", 0)
If strPacName <> "" Then
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
WordApp.Documents.Open "C:\Documents and
Settings\slilly\Desktop\Master Form Directory\Word Documents\Example
Package.doc", ReadOnly:=False
WordApp.ActiveDocument.SaveAs FileName:="C:\Documents and
Settings\slilly\Desktop\Blank Project\Word Files\" & strPacName & ".doc"
End If
Set WordApp = Nothing
End Sub
It opens the document but then it puts up an option box telling me that the
document is already in use and "do I want to open it in read only?"... Why oh
why does this program hate me so? If I select "read only", it saves it like
it is supposed to and it lets me edit it so it is a regular file... not read
only... any ideas on why it does this?
Jan De Messemaeker 06-28-2007, 08:26 PM Hi,
As far as I can see your sub does not close the file nor the Word
application (Wordapp.quit) so it is not abnomraml that a copy stays open.
--
Jan De Messemaeker
Microsoft Project MVP
http://users.online.be/prom-ade
"Steff" <Steff@discussions.microsoft.com> wrote in message
news:C3486FCE-50BD-4DA7-90ED-F2D63780BD2C@microsoft.com...
> Next Question on this journey...
>
> I am trying to open a document from a master document list and then save
> it
> using the name that the user inputs. Here is my code
>
>
> Private Sub CommandButton1_Click()
>
> 'Create A Package
>
> Dim WordApp As Word.Application
> Dim strPacName As String
> Dim Count As Long
> Dim NewPac As Long
> strPacName = InputBox("Equipment Name", "Package Creation", , , ,
> "c:\Windows\Help\Procedure Help.chm", 0)
>
> If strPacName <> "" Then
> Set WordApp = CreateObject("Word.Application")
> WordApp.Visible = True
> WordApp.Documents.Open "C:\Documents and
> Settings\slilly\Desktop\Master Form Directory\Word Documents\Example
> Package.doc", ReadOnly:=False
> WordApp.ActiveDocument.SaveAs FileName:="C:\Documents and
> Settings\slilly\Desktop\Blank Project\Word Files\" & strPacName & ".doc"
>
> End If
> Set WordApp = Nothing
>
> End Sub
>
> It opens the document but then it puts up an option box telling me that
> the
> document is already in use and "do I want to open it in read only?"... Why
> oh
> why does this program hate me so? If I select "read only", it saves it
> like
> it is supposed to and it lets me edit it so it is a regular file... not
> read
> only... any ideas on why it does this?
>
Steff 06-28-2007, 09:24 PM Oh... the copy is supposed to stay open. When the project manager wants to
create a new engineering package, I tied a macro to a button that pulls open
a blank package from a master document list, he types in the name of the
system he is writing a package for, it then saves it as a package under the
system name he gives it, and then he can edit it at will. It does everything
I want it to except that when it opens the master document it first opens a
box that says "Example Package.doc is locked for editing by another user" and
then makes me choose to open it as read only. It should just open and allow
for editing.
"Jan De Messemaeker" wrote:
> Hi,
>
> As far as I can see your sub does not close the file nor the Word
> application (Wordapp.quit) so it is not abnomraml that a copy stays open.
>
> --
> Jan De Messemaeker
> Microsoft Project MVP
> http://users.online.be/prom-ade
> "Steff" <Steff@discussions.microsoft.com> wrote in message
> news:C3486FCE-50BD-4DA7-90ED-F2D63780BD2C@microsoft.com...
> > Next Question on this journey...
> >
> > I am trying to open a document from a master document list and then save
> > it
> > using the name that the user inputs. Here is my code
> >
> >
> > Private Sub CommandButton1_Click()
> >
> > 'Create A Package
> >
> > Dim WordApp As Word.Application
> > Dim strPacName As String
> > Dim Count As Long
> > Dim NewPac As Long
> > strPacName = InputBox("Equipment Name", "Package Creation", , , ,
> > "c:\Windows\Help\Procedure Help.chm", 0)
> >
> > If strPacName <> "" Then
> > Set WordApp = CreateObject("Word.Application")
> > WordApp.Visible = True
> > WordApp.Documents.Open "C:\Documents and
> > Settings\slilly\Desktop\Master Form Directory\Word Documents\Example
> > Package.doc", ReadOnly:=False
> > WordApp.ActiveDocument.SaveAs FileName:="C:\Documents and
> > Settings\slilly\Desktop\Blank Project\Word Files\" & strPacName & ".doc"
> >
> > End If
> > Set WordApp = Nothing
> >
> > End Sub
> >
> > It opens the document but then it puts up an option box telling me that
> > the
> > document is already in use and "do I want to open it in read only?"... Why
> > oh
> > why does this program hate me so? If I select "read only", it saves it
> > like
> > it is supposed to and it lets me edit it so it is a regular file... not
> > read
> > only... any ideas on why it does this?
> >
>
>
>
Jan De Messemaeker 06-29-2007, 02:17 PM Hi,
Well, if it's open, and you open again, it proposes read only.
In the Word app, search for the open doculent rather than opening it.
HTH
--
Jan De Messemaeker
Microsoft Project MVP
http://users.online.be/prom-ade
"Steff" <Steff@discussions.microsoft.com> wrote in message
news:94DA5B71-90D4-4C12-BBAE-AFC58C4BB171@microsoft.com...
> Oh... the copy is supposed to stay open. When the project manager wants
> to
> create a new engineering package, I tied a macro to a button that pulls
> open
> a blank package from a master document list, he types in the name of the
> system he is writing a package for, it then saves it as a package under
> the
> system name he gives it, and then he can edit it at will. It does
> everything
> I want it to except that when it opens the master document it first opens
> a
> box that says "Example Package.doc is locked for editing by another user"
> and
> then makes me choose to open it as read only. It should just open and
> allow
> for editing.
>
> "Jan De Messemaeker" wrote:
>
>> Hi,
>>
>> As far as I can see your sub does not close the file nor the Word
>> application (Wordapp.quit) so it is not abnomraml that a copy stays open.
>>
>> --
>> Jan De Messemaeker
>> Microsoft Project MVP
>> http://users.online.be/prom-ade
>> "Steff" <Steff@discussions.microsoft.com> wrote in message
>> news:C3486FCE-50BD-4DA7-90ED-F2D63780BD2C@microsoft.com...
>> > Next Question on this journey...
>> >
>> > I am trying to open a document from a master document list and then
>> > save
>> > it
>> > using the name that the user inputs. Here is my code
>> >
>> >
>> > Private Sub CommandButton1_Click()
>> >
>> > 'Create A Package
>> >
>> > Dim WordApp As Word.Application
>> > Dim strPacName As String
>> > Dim Count As Long
>> > Dim NewPac As Long
>> > strPacName = InputBox("Equipment Name", "Package Creation", , , ,
>> > "c:\Windows\Help\Procedure Help.chm", 0)
>> >
>> > If strPacName <> "" Then
>> > Set WordApp = CreateObject("Word.Application")
>> > WordApp.Visible = True
>> > WordApp.Documents.Open "C:\Documents and
>> > Settings\slilly\Desktop\Master Form Directory\Word Documents\Example
>> > Package.doc", ReadOnly:=False
>> > WordApp.ActiveDocument.SaveAs FileName:="C:\Documents and
>> > Settings\slilly\Desktop\Blank Project\Word Files\" & strPacName &
>> > ".doc"
>> >
>> > End If
>> > Set WordApp = Nothing
>> >
>> > End Sub
>> >
>> > It opens the document but then it puts up an option box telling me that
>> > the
>> > document is already in use and "do I want to open it in read only?"...
>> > Why
>> > oh
>> > why does this program hate me so? If I select "read only", it saves it
>> > like
>> > it is supposed to and it lets me edit it so it is a regular file... not
>> > read
>> > only... any ideas on why it does this?
>> >
>>
>>
>>
|
|
|