Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Opening a file through input of first 3 digits

Hi all,

with some help (!) I managed to have a .doc file to open after
running a macro with a given input in a cell.

For instance:

cell b2 hs the value 101

Now after selecting the cell (B2) and running the macro.
The file 101_document will be opened.


However: the "_document" part is a random name.
My list of files looks a bit like this:

101_smith_retail
102_Johnson_hardware
103_Kelly_cycles

How can I open a file after input?

So the line: strFilename = "_document.doc"
should be more like: strFilename = random_name ????




Sub test()
'Dim MyFile As String

Dim wdapp As Object
strFilename = "_document.doc"
Set wdapp = CreateObject("Word.Application")
With wdapp
.Documents.Open Filename:="C:\" & ActiveCell.Value & strFilename
.Visible = True
End With
Set wdapp = Nothing
End Sub



I hope my description is clear enough for you to understand what i'm
looking for?


Thanks in advance for your help, Theo


--
Greetz, Just4fun
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Opening a file through input of first 3 digits

You cannot generate a random name string, it just doesn't make sense as
their is not a name string series as there is a number series. If you were
holding the names in a table somewhere, you could generate a random number
and then use that as an index into the table to get a name.

But why would you want to do this, surely it is highly unlikely that this
document will exist?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Just4fun" wrote in message
...
Hi all,

with some help (!) I managed to have a .doc file to open after
running a macro with a given input in a cell.

For instance:

cell b2 hs the value 101

Now after selecting the cell (B2) and running the macro.
The file 101_document will be opened.


However: the "_document" part is a random name.
My list of files looks a bit like this:

101_smith_retail
102_Johnson_hardware
103_Kelly_cycles

How can I open a file after input?

So the line: strFilename = "_document.doc"
should be more like: strFilename = random_name ????




Sub test()
'Dim MyFile As String

Dim wdapp As Object
strFilename = "_document.doc"
Set wdapp = CreateObject("Word.Application")
With wdapp
.Documents.Open Filename:="C:\" & ActiveCell.Value & strFilename
.Visible = True
End With
Set wdapp = Nothing
End Sub



I hope my description is clear enough for you to understand what i'm
looking for?


Thanks in advance for your help, Theo


--
Greetz, Just4fun



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Opening a file through input of first 3 digits

bob,

I think OP is writing a procedure for SPAMMING.
else why need random names like the one he's proposing?

just4fun... nah!

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bob Phillips" wrote:

You cannot generate a random name string, it just doesn't make sense
as their is not a name string series as there is a number series. If
you were holding the names in a table somewhere, you could generate a
random number and then use that as an index into the table to get a
name.

But why would you want to do this, surely it is highly unlikely that
this document will exist?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Opening a file through input of first 3 digits

I think he meant the part after the three digits would not be always the
same - perhaps random was a poorly chosen descriptive term to indicate this.

--
Regards,
Tom Ogilvy

"keepITcool" wrote in message
...
bob,

I think OP is writing a procedure for SPAMMING.
else why need random names like the one he's proposing?

just4fun... nah!

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bob Phillips" wrote:

You cannot generate a random name string, it just doesn't make sense
as their is not a name string series as there is a number series. If
you were holding the names in a table somewhere, you could generate a
random number and then use that as an index into the table to get a
name.

But why would you want to do this, surely it is highly unlikely that
this document will exist?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Opening a file through input of first 3 digits

"Tom Ogilvy" wrote in
:

I think he meant the part after the three digits would not be always
the same - perhaps random was a poorly chosen descriptive term to
indicate this.



And right as you are Tom ;))


(did I already tell ya i'm kinda of a newebee ?)


--
Greetz, Just4fun


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Opening a file through input of first 3 digits

keepITcool wrote in
:

bob,

I think OP is writing a procedure for SPAMMING.
else why need random names like the one he's proposing?

just4fun... nah!

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bob Phillips" wrote:

You cannot generate a random name string, it just doesn't make sense
as their is not a name string series as there is a number series. If
you were holding the names in a table somewhere, you could generate a
random number and then use that as an index into the table to get a
name.

But why would you want to do this, surely it is highly unlikely that
this document will exist?



Is what I am doing called "spamming" ?
(posting the same question in 2 newsgroups)


If so... sorry for that.

(forgive me for my noobnes)


Theo.


--

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Opening a file through input of first 3 digits


dim sStr as String, sStr1 as String
sStr = Trim(Activecell.Text)
sStr1 = Dir("c:\Myfiles\" & sStr & "_*.xls)
if sStr1 < "" then
workbooks.Open "C:\MyFiles\" & sStr1
End if

I am not sure where you want to open a doc file, but you can't open it in
Excel. I used .xls as the extension, but perhaps this is a word question
and you are posting in the wrong group.

--
Regards,
Tom Ogilvy

"Just4fun" wrote in message
...
Hi all,

with some help (!) I managed to have a .doc file to open after
running a macro with a given input in a cell.

For instance:

cell b2 hs the value 101

Now after selecting the cell (B2) and running the macro.
The file 101_document will be opened.


However: the "_document" part is a random name.
My list of files looks a bit like this:

101_smith_retail
102_Johnson_hardware
103_Kelly_cycles

How can I open a file after input?

So the line: strFilename = "_document.doc"
should be more like: strFilename = random_name ????




Sub test()
'Dim MyFile As String

Dim wdapp As Object
strFilename = "_document.doc"
Set wdapp = CreateObject("Word.Application")
With wdapp
.Documents.Open Filename:="C:\" & ActiveCell.Value & strFilename
.Visible = True
End With
Set wdapp = Nothing
End Sub



I hope my description is clear enough for you to understand what i'm
looking for?


Thanks in advance for your help, Theo


--
Greetz, Just4fun



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Opening a file through input of first 3 digits

"Tom Ogilvy" wrote in
: Hi Tom,


you'r wrong on the fact that it's not possible to open a
..doc file from within Escel.....it can be done.

Thanks to Don and Juan I made it happen.






I am not sure where you want to open a doc file, but you can't open it
in Excel. I used .xls as the extension, but perhaps this is a word
question and you are posting in the wrong group.




--
Greetz, Just4fun
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Opening a file through input of first 3 digits

If the doc file is a word document as is usually implied by the doc
extension, then it can not be opened in excel. Please demonstrate that this
is incorrect.

Where did Don and Juan demonstrate this magical capability.

--
Regards,
Tom Ogilvy

"Just4fun" wrote in message
...
"Tom Ogilvy" wrote in
: Hi Tom,


you'r wrong on the fact that it's not possible to open a
.doc file from within Escel.....it can be done.

Thanks to Don and Juan I made it happen.






I am not sure where you want to open a doc file, but you can't open it
in Excel. I used .xls as the extension, but perhaps this is a word
question and you are posting in the wrong group.




--
Greetz, Just4fun



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Opening a file through input of first 3 digits

Based on the code you posted:

Dim wdapp As Object
strFilename = "_document.doc"
Set wdapp = CreateObject("Word.Application")
With wdapp
.Documents.Open Filename:="C:\my documents\" & ActiveCell.Value &
strFilename
.Visible = True
End With
Set wdapp = Nothing
End Sub


It is obvious that you are not opening the document in Excel. Using Excel
to manipulate word to open the document does not open it in Excel as you
have stated.

Also, your code does not answer the current question you ask. So I wonder
why you say Don and Juan have provided the answer.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
If the doc file is a word document as is usually implied by the doc
extension, then it can not be opened in excel. Please demonstrate that

this
is incorrect.

Where did Don and Juan demonstrate this magical capability.

--
Regards,
Tom Ogilvy

"Just4fun" wrote in message
...
"Tom Ogilvy" wrote in
: Hi Tom,


you'r wrong on the fact that it's not possible to open a
.doc file from within Escel.....it can be done.

Thanks to Don and Juan I made it happen.






I am not sure where you want to open a doc file, but you can't open it
in Excel. I used .xls as the extension, but perhaps this is a word
question and you are posting in the wrong group.




--
Greetz, Just4fun







  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Opening a file through input of first 3 digits

Oke...

I will try to explain what:


While working in Excel.

A planner puts a value (f.i. 101) in cell B2
Where column B is "Customer requierment".
And these Customer req. are saved as:


101_smith_retail.doc
102_Johnson_hardware.doc
103_Kelly_cycles.doc


After that I select B2 and run my macro.
(see the macro below)

And this results in a word document (101_document.doc) to be opened.
(correct Tom, ....not IN excel, but as a normal WORD document.)

But: like the list (101, 102, 103...) shows, the last part of
each document name differs.


Maybe I use the wrong words to describe my exact wishes and so.
(but being Dutch, I do my best)





T.i.a. Theo.
- - - - - - - - - - - - - - - - - - -

Dim wdapp As Object
strFilename = "_document.doc"
Set wdapp = CreateObject("Word.Application")
With wdapp
.Documents.Open Filename:="C:\" & ActiveCell.Value & strFilename
.Visible = True
End With
Set wdapp = Nothing
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
after opening existing spreadsheet can't input data anymore rls Excel Worksheet Functions 2 October 6th 08 03:36 AM
Opening a file with User Input [email protected] Excel Discussion (Misc queries) 3 March 28th 07 03:00 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
Opening a template form & renaming it from a cell input automatica John Galt Excel Discussion (Misc queries) 0 April 19th 05 09:16 PM
Opening a text file for input [email protected] Excel Programming 5 January 8th 04 05:11 AM


All times are GMT +1. The time now is 02:19 AM.

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

About Us

"It's about Microsoft Excel"