Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default How to paste HTML code as text into a worksheet?

Excel 2003

In Internet Explorer, I view the source code of my Web page in Notepad,
then copy that text and paste it into an Excel worksheet.

Excel gives me only two choices in Paste Special (text and unicode),
both of which causes a problem. They both paste as interpreted HTML
code and so my worksheet tries to render as a Web page. I don't want
that.

So after pasting and after the rendering, I click the paste option
button that appears, and choose "Use text import wizard". In the wizard
I choose "Fixed Width" and click Finish. The HTML code now appears in
my worksheet correctly as HTML code (text).

I want this clipboard-pasting routine in VBA, but can't figure it out.
It won't record the paste option button, so that's no help.

How do I paste using VBA as described above or using another paste
method where I get all the source code text on my clipboard into a
worksheet as text?

Many thanks,
Chuck

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to paste HTML code as text into a worksheet?

Hi c mateland

Save the Notepad file (txt)
On this page there is a code example to open the txt file in Excel with VBA

http://www.rondebruin.nl/csv.htm

See this part
Workbooks.OpenText Filename

Record a macro when you do it manual to see the code you need


--
Regards Ron de Bruin
http://www.rondebruin.nl



"c mateland" wrote in message oups.com...
Excel 2003

In Internet Explorer, I view the source code of my Web page in Notepad,
then copy that text and paste it into an Excel worksheet.

Excel gives me only two choices in Paste Special (text and unicode),
both of which causes a problem. They both paste as interpreted HTML
code and so my worksheet tries to render as a Web page. I don't want
that.

So after pasting and after the rendering, I click the paste option
button that appears, and choose "Use text import wizard". In the wizard
I choose "Fixed Width" and click Finish. The HTML code now appears in
my worksheet correctly as HTML code (text).

I want this clipboard-pasting routine in VBA, but can't figure it out.
It won't record the paste option button, so that's no help.

How do I paste using VBA as described above or using another paste
method where I get all the source code text on my clipboard into a
worksheet as text?

Many thanks,
Chuck



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default How to paste HTML code as text into a worksheet?

Is there any way to do this straight from the clipboard without first
saving in Notepad as a txt file?

This routine is in the middle of a larger macro. While focus is on
Notepad, it's easy to select all and copy and close Notepad using VBA,
but I'm not sure how I would use VBA to save the txt file while the
focus is on Notepad (save as, navigate to folder, name file, save).

Any solutions?

Thanks,
Chuck


Ron de Bruin wrote:
Hi c mateland

Save the Notepad file (txt)
On this page there is a code example to open the txt file in Excel with VBA

http://www.rondebruin.nl/csv.htm

See this part
Workbooks.OpenText Filename

Record a macro when you do it manual to see the code you need


--
Regards Ron de Bruin
http://www.rondebruin.nl



"c mateland" wrote in message oups.com...
Excel 2003

In Internet Explorer, I view the source code of my Web page in Notepad,
then copy that text and paste it into an Excel worksheet.

Excel gives me only two choices in Paste Special (text and unicode),
both of which causes a problem. They both paste as interpreted HTML
code and so my worksheet tries to render as a Web page. I don't want
that.

So after pasting and after the rendering, I click the paste option
button that appears, and choose "Use text import wizard". In the wizard
I choose "Fixed Width" and click Finish. The HTML code now appears in
my worksheet correctly as HTML code (text).

I want this clipboard-pasting routine in VBA, but can't figure it out.
It won't record the paste option button, so that's no help.

How do I paste using VBA as described above or using another paste
method where I get all the source code text on my clipboard into a
worksheet as text?

Many thanks,
Chuck


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to paste HTML code as text into a worksheet?

Try this Chuck


Application.Dialogs(xlDialogImportTextFile).Show


You can change this line to the Workbooks.OpenText Filename........................
to import it automatic



Sub Create_TXT_File()
Dim myFileName As String
Dim FileNum As Long

myFileName = "C:\Data\ron.txt"

FileNum = FreeFile
Close FileNum
Open myFileName For Output As FileNum

Print #FileNum, GetSource("http://www.rondebruin.nl")

Close FileNum

Application.Dialogs(xlDialogImportTextFile).Show

End Sub


Function GetSource(sURL As String) As String
'Tim Williams
Dim oXHTTP As Object

Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "GET", sURL, False
oXHTTP.send
GetSource = oXHTTP.responsetext
Set oXHTTP = Nothing

End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl



"c mateland" wrote in message ups.com...
Is there any way to do this straight from the clipboard without first
saving in Notepad as a txt file?

This routine is in the middle of a larger macro. While focus is on
Notepad, it's easy to select all and copy and close Notepad using VBA,
but I'm not sure how I would use VBA to save the txt file while the
focus is on Notepad (save as, navigate to folder, name file, save).

Any solutions?

Thanks,
Chuck


Ron de Bruin wrote:
Hi c mateland

Save the Notepad file (txt)
On this page there is a code example to open the txt file in Excel with VBA

http://www.rondebruin.nl/csv.htm

See this part
Workbooks.OpenText Filename

Record a macro when you do it manual to see the code you need


--
Regards Ron de Bruin
http://www.rondebruin.nl



"c mateland" wrote in message oups.com...
Excel 2003

In Internet Explorer, I view the source code of my Web page in Notepad,
then copy that text and paste it into an Excel worksheet.

Excel gives me only two choices in Paste Special (text and unicode),
both of which causes a problem. They both paste as interpreted HTML
code and so my worksheet tries to render as a Web page. I don't want
that.

So after pasting and after the rendering, I click the paste option
button that appears, and choose "Use text import wizard". In the wizard
I choose "Fixed Width" and click Finish. The HTML code now appears in
my worksheet correctly as HTML code (text).

I want this clipboard-pasting routine in VBA, but can't figure it out.
It won't record the paste option button, so that's no help.

How do I paste using VBA as described above or using another paste
method where I get all the source code text on my clipboard into a
worksheet as text?

Many thanks,
Chuck




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to paste HTML code as text into a worksheet?

Change the path of the txt file it create

myFileName = "C:\Data\ron.txt"




--
Regards Ron de Bruin
http://www.rondebruin.nl



"Ron de Bruin" wrote in message ...
Try this Chuck


Application.Dialogs(xlDialogImportTextFile).Show


You can change this line to the Workbooks.OpenText Filename........................
to import it automatic



Sub Create_TXT_File()
Dim myFileName As String
Dim FileNum As Long

myFileName = "C:\Data\ron.txt"

FileNum = FreeFile
Close FileNum
Open myFileName For Output As FileNum

Print #FileNum, GetSource("http://www.rondebruin.nl")

Close FileNum

Application.Dialogs(xlDialogImportTextFile).Show

End Sub


Function GetSource(sURL As String) As String
'Tim Williams
Dim oXHTTP As Object

Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "GET", sURL, False
oXHTTP.send
GetSource = oXHTTP.responsetext
Set oXHTTP = Nothing

End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl



"c mateland" wrote in message ups.com...
Is there any way to do this straight from the clipboard without first
saving in Notepad as a txt file?

This routine is in the middle of a larger macro. While focus is on
Notepad, it's easy to select all and copy and close Notepad using VBA,
but I'm not sure how I would use VBA to save the txt file while the
focus is on Notepad (save as, navigate to folder, name file, save).

Any solutions?

Thanks,
Chuck


Ron de Bruin wrote:
Hi c mateland

Save the Notepad file (txt)
On this page there is a code example to open the txt file in Excel with VBA

http://www.rondebruin.nl/csv.htm

See this part
Workbooks.OpenText Filename

Record a macro when you do it manual to see the code you need


--
Regards Ron de Bruin
http://www.rondebruin.nl



"c mateland" wrote in message oups.com...
Excel 2003

In Internet Explorer, I view the source code of my Web page in Notepad,
then copy that text and paste it into an Excel worksheet.

Excel gives me only two choices in Paste Special (text and unicode),
both of which causes a problem. They both paste as interpreted HTML
code and so my worksheet tries to render as a Web page. I don't want
that.

So after pasting and after the rendering, I click the paste option
button that appears, and choose "Use text import wizard". In the wizard
I choose "Fixed Width" and click Finish. The HTML code now appears in
my worksheet correctly as HTML code (text).

I want this clipboard-pasting routine in VBA, but can't figure it out.
It won't record the paste option button, so that's no help.

How do I paste using VBA as described above or using another paste
method where I get all the source code text on my clipboard into a
worksheet as text?

Many thanks,
Chuck








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
Paste as text not HTML RealGomer Excel Discussion (Misc queries) 0 November 18th 09 03:55 PM
Paste HTML Code mpeplow[_31_] Excel Programming 0 August 14th 06 09:16 PM
How to paste html code to xls pm Excel Discussion (Misc queries) 0 January 21st 06 08:22 PM
Import HTML code from a text file. [email protected] Excel Programming 2 April 1st 05 07:47 AM
How can I make Excel display HTML code as text roopytoopdongle Excel Discussion (Misc queries) 1 March 20th 05 06:40 AM


All times are GMT +1. The time now is 10:11 PM.

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"