PC Review


Reply
Thread Tools Rate Thread

How to change a Macro based on content of a cell

 
 
Alex
Guest
Posts: n/a
 
      15th May 2006
Hi,

I need to import a text file into a spreadsheet. I can do this manually by
doing File > Open > then select a text file. Then Excel goes through the
Text Import Wizard

I can automate this by recording a Macro in Excel. The macro looks like this
(Excell wrote that for me, I did not):

Sub Macro1()
Workbooks.OpenText Filename:="C:\DrillData\" + "MOR701.pck",
Origin:=xlMSDOS, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
Array(12 _
, 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
End Sub

How can I change this macro to look at the content of cell Logs!A8 (Cell A8
in the tab called "Logs")

I guess it would look something like this:

Sub Macro1()
Workbooks.OpenText Filename:="C:\DrillData\" + _

content_cell (Logs!A8)&".pck", _

Origin:=xlMSDOS, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
Array(12 _
, 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
End Sub



Thanks for your help

Alex.


 
Reply With Quote
 
 
 
 
Alex
Guest
Posts: n/a
 
      15th May 2006
Hi all,

I guess I was not very clear in my request.

My real challendge is that I have 100's of text files each containing data
formated in the same way. I need to open a given text file to use its data
based on the content of one of the cells of my spreadsheet. While I can do
the process manually (look at cell Logs!A8, import corresponding text file I
want to automate this process, I don't know how to automate this.

I found out how to automate the process if I always import the same text
file (see below), I found a way in theory how to automate it for any text
file (by placing the name of the file in cell Logs!A8), I just don't know
how to use the content of that cell to modify the Macro below.

Thank for your help

Alex

"Alex" <no-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I need to import a text file into a spreadsheet. I can do this manually by
> doing File > Open > then select a text file. Then Excel goes through the
> Text Import Wizard
>
> I can automate this by recording a Macro in Excel. The macro looks like
> this (Excell wrote that for me, I did not):
>
> Sub Macro1()
> Workbooks.OpenText Filename:="C:\DrillData\" + "MOR701.pck",
> Origin:=xlMSDOS, _
> StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
> Array(12 _
> , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
> End Sub
>
> How can I change this macro to look at the content of cell Logs!A8 (Cell
> A8 in the tab called "Logs")
>
> I guess it would look something like this:
>
> Sub Macro1()
> Workbooks.OpenText Filename:="C:\DrillData\" + _
>
> content_cell (Logs!A8)&".pck", _
>
> Origin:=xlMSDOS, _
> StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
> Array(12 _
> , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
> End Sub
>
>
>
> Thanks for your help
>
> Alex.
>



 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      15th May 2006
Hi Alex,

Try:

Dim sStr As String

sStr = ThisWorkbook.Sheets("Logs").Range("A8").Value & ".pck"

Workbooks.OpenText Filename:="C:\DrillData\" & sStr, ...



---
Regards,
Norman



"Alex" <no-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> I guess I was not very clear in my request.
>
> My real challendge is that I have 100's of text files each containing data
> formated in the same way. I need to open a given text file to use its data
> based on the content of one of the cells of my spreadsheet. While I can do
> the process manually (look at cell Logs!A8, import corresponding text file
> I want to automate this process, I don't know how to automate this.
>
> I found out how to automate the process if I always import the same text
> file (see below), I found a way in theory how to automate it for any text
> file (by placing the name of the file in cell Logs!A8), I just don't know
> how to use the content of that cell to modify the Macro below.
>
> Thank for your help
>
> Alex
>
> "Alex" <no-(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi,
>>
>> I need to import a text file into a spreadsheet. I can do this manually
>> by doing File > Open > then select a text file. Then Excel goes through
>> the Text Import Wizard
>>
>> I can automate this by recording a Macro in Excel. The macro looks like
>> this (Excell wrote that for me, I did not):
>>
>> Sub Macro1()
>> Workbooks.OpenText Filename:="C:\DrillData\" + "MOR701.pck",
>> Origin:=xlMSDOS, _
>> StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
>> Array(12 _
>> , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
>> End Sub
>>
>> How can I change this macro to look at the content of cell Logs!A8 (Cell
>> A8 in the tab called "Logs")
>>
>> I guess it would look something like this:
>>
>> Sub Macro1()
>> Workbooks.OpenText Filename:="C:\DrillData\" + _
>>
>> content_cell (Logs!A8)&".pck", _
>>
>> Origin:=xlMSDOS, _
>> StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
>> Array(12 _
>> , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
>> End Sub
>>
>>
>>
>> Thanks for your help
>>
>> Alex.
>>

>
>



 
Reply With Quote
 
Alex
Guest
Posts: n/a
 
      15th May 2006
Norman

Thank you for your help. It worked perfectly

Alex

"Norman Jones" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Alex,
>
> Try:
>
> Dim sStr As String
>
> sStr = ThisWorkbook.Sheets("Logs").Range("A8").Value & ".pck"
>
> Workbooks.OpenText Filename:="C:\DrillData\" & sStr, ...
>
>
>
> ---
> Regards,
> Norman
>
>
>
> "Alex" <no-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi all,
>>
>> I guess I was not very clear in my request.
>>
>> My real challendge is that I have 100's of text files each containing
>> data formated in the same way. I need to open a given text file to use
>> its data based on the content of one of the cells of my spreadsheet.
>> While I can do the process manually (look at cell Logs!A8, import
>> corresponding text file I want to automate this process, I don't know how
>> to automate this.
>>
>> I found out how to automate the process if I always import the same text
>> file (see below), I found a way in theory how to automate it for any text
>> file (by placing the name of the file in cell Logs!A8), I just don't know
>> how to use the content of that cell to modify the Macro below.
>>
>> Thank for your help
>>
>> Alex
>>
>> "Alex" <no-(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> Hi,
>>>
>>> I need to import a text file into a spreadsheet. I can do this manually
>>> by doing File > Open > then select a text file. Then Excel goes through
>>> the Text Import Wizard
>>>
>>> I can automate this by recording a Macro in Excel. The macro looks like
>>> this (Excell wrote that for me, I did not):
>>>
>>> Sub Macro1()
>>> Workbooks.OpenText Filename:="C:\DrillData\" + "MOR701.pck",
>>> Origin:=xlMSDOS, _
>>> StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0,
>>> 1), Array(12 _
>>> , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
>>> End Sub
>>>
>>> How can I change this macro to look at the content of cell Logs!A8 (Cell
>>> A8 in the tab called "Logs")
>>>
>>> I guess it would look something like this:
>>>
>>> Sub Macro1()
>>> Workbooks.OpenText Filename:="C:\DrillData\" + _
>>>
>>> content_cell (Logs!A8)&".pck", _
>>>
>>> Origin:=xlMSDOS, _
>>> StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0,
>>> 1), Array(12 _
>>> , 1), Array(26, 1), Array(37, 1)), TrailingMinusNumbers:=True
>>> End Sub
>>>
>>>
>>>
>>> Thanks for your help
>>>
>>> Alex.
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to change a cell color based on its content using macro? =?Utf-8?B?UmFuZ2VyODg4?= Microsoft Excel New Users 7 10th Mar 2010 02:12 PM
Macro to change directory based on cell content =?Utf-8?B?bWF0aGVs?= Microsoft Excel Programming 3 20th Oct 2007 02:33 PM
how do I change the content of one cell based on another? Barry Microsoft Excel Misc 2 3rd Sep 2006 10:16 AM
Change the data in one cell based on content of another. =?Utf-8?B?QmFycnk=?= Microsoft Excel Misc 2 3rd Sep 2006 08:26 AM
How do I change content of a cell based on date =?Utf-8?B?ZGl2aW5nMQ==?= Microsoft Excel Worksheet Functions 2 19th Dec 2004 08:39 PM


Features
 

Advertising
 

Newsgroups
 


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