Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Code to save Word-document do not work properly

I have this code:

Sub Flet()

Dim Wdapp As Object
Dim Navn As String


On Error Resume Next
Set Wdapp = GetObject(, "Word.application")
If Err.Number < 0 Then
Set Wdapp = CreateObject("Word.Application")
End If

For Each c In Range("A2:A200")
Wdapp.Documents.Add "flet.dot"
If c.Value = "" Then Exit For Else
Navn = c.Value

.... A lot of code for replacing bookmarks

Navn = Navn & " " & Date & " " & Time
Wdapp.ActiveDocument.SaveAs Filename:="C:\test\" & Navn &
".docx"
Wdapp.ActiveDocument.Close
Next c

Wdapp.Visible = False
MsgBox "Merge has completede and the documents are saved in C:
\Test", vbOKOnly + vbInformation
Wdapp.Quit
Set Wdapp = Nothing


End Sub

The code is supposed to make a document for each used line in the
specified range, and save the document in C:\Test, and when all the
documents are saved, it should tell me so.

If i comment out :

Navn = Navn & " " & Date & " " & Time

it works as supposed, but as soon as I try to add a date-time stamp to
the name it starts to display the SaveAs Dialog for each document,
suggesting I save them in MyDocuments. And when I click Cancel to
these dialogs, it asks me if I want to close the document without
saving.

Any ideas what goes wrong?

Jan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Code to save Word-document do not work properly


You may be exceeding the 31 character limit for a sheet name.
Date and Time plus the blanks uses 22 characters on my system.
--
Jim Cone
Portland, Oregon USA



"jkrons"
wrote in message ...
I have this code:

Sub Flet()
Dim Wdapp As Object
Dim Navn As String
On Error Resume Next
Set Wdapp = GetObject(, "Word.application")
If Err.Number < 0 Then
Set Wdapp = CreateObject("Word.Application")
End If
For Each c In Range("A2:A200")
Wdapp.Documents.Add "flet.dot"
If c.Value = "" Then Exit For Else Navn = c.Value

.... A lot of code for replacing bookmarks

Navn = Navn & " " & Date & " " & Time
Wdapp.ActiveDocument.SaveAs Filename:="C:\test\" & Navn & ".docx"
Wdapp.ActiveDocument.Close
Next c
Wdapp.Visible = False
MsgBox "Merge has completede and the documents are saved in C:
\Test", vbOKOnly + vbInformation
Wdapp.Quit
Set Wdapp = Nothing
End Sub

The code is supposed to make a document for each used line in the
specified range, and save the document in C:\Test, and when all the
documents are saved, it should tell me so.
If i comment out :

Navn = Navn & " " & Date & " " & Time

it works as supposed, but as soon as I try to add a date-time stamp to
the name it starts to display the SaveAs Dialog for each document,
suggesting I save them in MyDocuments. And when I click Cancel to
these dialogs, it asks me if I want to close the document without
saving.
Any ideas what goes wrong?
Jan
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Code to save Word-document do not work properly

Depending on your local settings, Date & " " & Time will add some illegal
characters into the file name. Try something like this:
Navn = Navn & " " & Format(Date + Time,"dd_mm_yy hh_mm")

Cheers,
Dave

"jkrons" wrote:

I have this code:

Sub Flet()

Dim Wdapp As Object
Dim Navn As String


On Error Resume Next
Set Wdapp = GetObject(, "Word.application")
If Err.Number < 0 Then
Set Wdapp = CreateObject("Word.Application")
End If

For Each c In Range("A2:A200")
Wdapp.Documents.Add "flet.dot"
If c.Value = "" Then Exit For Else
Navn = c.Value

.... A lot of code for replacing bookmarks

Navn = Navn & " " & Date & " " & Time
Wdapp.ActiveDocument.SaveAs Filename:="C:\test\" & Navn &
".docx"
Wdapp.ActiveDocument.Close
Next c

Wdapp.Visible = False
MsgBox "Merge has completede and the documents are saved in C:
\Test", vbOKOnly + vbInformation
Wdapp.Quit
Set Wdapp = Nothing


End Sub

The code is supposed to make a document for each used line in the
specified range, and save the document in C:\Test, and when all the
documents are saved, it should tell me so.

If i comment out :

Navn = Navn & " " & Date & " " & Time

it works as supposed, but as soon as I try to add a date-time stamp to
the name it starts to display the SaveAs Dialog for each document,
suggesting I save them in MyDocuments. And when I click Cancel to
these dialogs, it asks me if I want to close the document without
saving.

Any ideas what goes wrong?

Jan
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Code to save Word-document do not work properly

Thanks. It worked.

Jan

Dave Ramage wrote:
Depending on your local settings, Date & " " & Time will add some
illegal characters into the file name. Try something like this:
Navn = Navn & " " & Format(Date + Time,"dd_mm_yy hh_mm")

Cheers,
Dave

"jkrons" wrote:

I have this code:

Sub Flet()

Dim Wdapp As Object
Dim Navn As String


On Error Resume Next
Set Wdapp = GetObject(, "Word.application")
If Err.Number < 0 Then
Set Wdapp = CreateObject("Word.Application")
End If

For Each c In Range("A2:A200")
Wdapp.Documents.Add "flet.dot"
If c.Value = "" Then Exit For Else
Navn = c.Value

.... A lot of code for replacing bookmarks

Navn = Navn & " " & Date & " " & Time
Wdapp.ActiveDocument.SaveAs Filename:="C:\test\" & Navn &
".docx"
Wdapp.ActiveDocument.Close
Next c

Wdapp.Visible = False
MsgBox "Merge has completede and the documents are saved in
C: \Test", vbOKOnly + vbInformation
Wdapp.Quit
Set Wdapp = Nothing


End Sub

The code is supposed to make a document for each used line in the
specified range, and save the document in C:\Test, and when all the
documents are saved, it should tell me so.

If i comment out :

Navn = Navn & " " & Date & " " & Time

it works as supposed, but as soon as I try to add a date-time stamp
to the name it starts to display the SaveAs Dialog for each document,
suggesting I save them in MyDocuments. And when I click Cancel to
these dialogs, it asks me if I want to close the document without
saving.

Any ideas what goes wrong?

Jan
.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to save xls file to a word document like an attachm weit Excel Discussion (Misc queries) 2 February 22nd 06 06:57 PM
paste to word document and save eyecalibrate[_7_] Excel Programming 1 December 31st 05 07:17 PM
How do you replace a work sheet in excel with a word document? DonxCahill Excel Discussion (Misc queries) 2 July 11th 05 05:03 PM
How do I make 'save as web page' with interactivity work properly. Giasemi Charts and Charting in Excel 0 January 6th 05 03:51 PM
Can't get code to work properly. Please Help! sparky3883[_8_] Excel Programming 2 April 15th 04 01:55 PM


All times are GMT +1. The time now is 05:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"