Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
TJA TJA is offline
external usenet poster
 
Posts: 5
Default Saving excel data to load into word

Please help....

I wrote this macro in excel exporting excel data so it can be loaded into
word document. It is not working... I can't get it to debub.

Thank you


Sub File_Export()
'
' File_Export Macro
' Export Style Worksheet to Word
'
' Keyboard Shortcut: Ctrl+Shift+F
'
'Export file for MS Word
'

Dim Filename As String
Dim NumRows As Long, NumCols As Integer
Dim r As Long, c As Integer
Dim Data
Dim ExpRng As Range

ThisWorkbook.Worksheets("person").Activate
Set ExpRng = Range("A5:N30")
NumCols = ExpRng.Columns.Count
NumRows = ExpRng.Rows.Count
Filename = "f:\foundations\excel_program\styles.txt"
Open Filename For Output As #1
For r = 1 To NumRows
For c = 1 To NumCols
Data = ExpRng.Cells(r, c).Value
If IsNumeric(Data) Then Data = Val(Data)
If IsEmpty(ExpRng.Cells(r, c)) Then Data = ""
If c < NumCols Then
Write #1, Data;
Else
Write #1, Data
End If
Next c
Next r
Close #1
ThisWorkbook.Worksheets("blank").Activate
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,365
Default Saving excel data to load into word

Your code works just fine on my system (Excel 2003). What error are you
getting when you try to run it?

You say you can't get it to Debug? If you're using Debug | Compile VBA
Project and nothing seems to be happening, that just means that the process
has not detected any obvious errors in syntax.

I might have written it slightly differently, as show below, but that's just
me. First I'd declare a new integer variable, newFileNum, to hold an
available file number obtained from the system (see code), and I would have
written the tests for cell contents to test for the IsEmpty() state first,
but other than that, it looks like code that should give you the results you
want. As I said, your code works for me as written.

My revised version of your code:
Dim Filename As String
Dim NumRows As Long, NumCols As Integer
Dim r As Long, c As Integer
Dim Data
Dim ExpRng As Range
Dim newFileNum As Integer ' added variable

ThisWorkbook.Worksheets("person").Activate
Set ExpRng = Range("A5:N30")
NumCols = ExpRng.Columns.Count
NumRows = ExpRng.Rows.Count
newFileNum = FreeFile() ' get available buffer #
Filename = "C:\Documents and Settings\All Users\Documents\styles.txt"
Open Filename For Output As #newFileNum ' changed
For r = 1 To NumRows
For c = 1 To NumCols
'changed testing for a cell's contents
If IsEmpty(ExpRng.Cells(r, c)) Then
Data = ""
ElseIf IsNumeric(ExpRng.Cells(r, c)) Then
Data = Val(ExpRng.Cells(r, c))
Else
Data = ExpRng.Cells(r, c)
End If
If c < NumCols Then
Write #newFileNum, Data; ' changed
Else
Write #newFileNum, Data ' changed
End If
Next c
Next r
Close #newFileNum ' changed
ThisWorkbook.Worksheets("blank").Activate



"TJA" wrote:

Please help....

I wrote this macro in excel exporting excel data so it can be loaded into
word document. It is not working... I can't get it to debub.

Thank you


Sub File_Export()
'
' File_Export Macro
' Export Style Worksheet to Word
'
' Keyboard Shortcut: Ctrl+Shift+F
'
'Export file for MS Word
'

Dim Filename As String
Dim NumRows As Long, NumCols As Integer
Dim r As Long, c As Integer
Dim Data
Dim ExpRng As Range

ThisWorkbook.Worksheets("person").Activate
Set ExpRng = Range("A5:N30")
NumCols = ExpRng.Columns.Count
NumRows = ExpRng.Rows.Count
Filename = "f:\foundations\excel_program\styles.txt"
Open Filename For Output As #1
For r = 1 To NumRows
For c = 1 To NumCols
Data = ExpRng.Cells(r, c).Value
If IsNumeric(Data) Then Data = Val(Data)
If IsEmpty(ExpRng.Cells(r, c)) Then Data = ""
If c < NumCols Then
Write #1, Data;
Else
Write #1, Data
End If
Next c
Next r
Close #1
ThisWorkbook.Worksheets("blank").Activate
End Sub

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
Saving an excel file in word Darlene Excel Discussion (Misc queries) 2 April 24th 07 01:02 PM
Saving Excel E Mails in a Word Folder HNL Setting up and Configuration of Excel 1 September 16th 06 10:23 AM
saving work in word/excel onto a usb flashdrive Julie Excel Discussion (Misc queries) 2 December 19th 05 03:49 PM
Excel should undo/redo after saving a file--just like Word. [email protected] Excel Discussion (Misc queries) 3 May 26th 05 12:11 AM
Is anything needed if I only load Word & Excel from Office XP Sta. Art SC Excel Discussion (Misc queries) 0 January 26th 05 01:59 AM


All times are GMT +1. The time now is 03:47 AM.

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"