Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading File and adding contents to spreadsheet

I need to read a number (counter) from a file (.txt probably), and add it to
my spreadsheet. Then increment that number by one, and store the result back
into the file. The purpose is so different users can open the spreadsheet
and get the next available number to number the form. Here's how I did it in
Word. How do I do it in Excel?

Public Sub MAIN()
Dim CheckNum$
Dim docnum$
CheckNum$ = WordBasic.[GetFormResult$]("DocNumField")
If CheckNum$ = "00000" Then
docnum$ = WordBasic.[GetPrivateProfileString$]("DocTracker", "DocNum", _
"U:\Counter\TemplateCounter.INI")
docnum$ = Str((WordBasic.Val(docnum$) + 1))
WordBasic.SetFormResult "DocNumField", docnum$
WordBasic.SetPrivateProfileString "DocTracker", "DocNum", docnum$, _
"U:\Counter\TemplateCounter.INI"
ActiveWindow.ActivePane.HorizontalPercentScrolled = 34
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Reading File and adding contents to spreadsheet

On Jun 12, 4:26 pm, KermanPM
wrote:
I need to read a number (counter) from a file (.txt probably), and add it to
my spreadsheet. Then increment that number by one, and store the result back
into the file. The purpose is so different users can open the spreadsheet
and get the next available number to number the form. Here's how I did it in
Word. How do I do it in Excel?

Public Sub MAIN()
Dim CheckNum$
Dim docnum$
CheckNum$ = WordBasic.[GetFormResult$]("DocNumField")
If CheckNum$ = "00000" Then
docnum$ = WordBasic.[GetPrivateProfileString$]("DocTracker", "DocNum", _
"U:\Counter\TemplateCounter.INI")
docnum$ = Str((WordBasic.Val(docnum$) + 1))
WordBasic.SetFormResult "DocNumField", docnum$
WordBasic.SetPrivateProfileString "DocTracker", "DocNum", docnum$, _
"U:\Counter\TemplateCounter.INI"
ActiveWindow.ActivePane.HorizontalPercentScrolled = 34
End If
End Sub


Hello KermanPM,

VBA has 2 functions that are designed to make storage and retrieval of
program information easy and quick. You could have used these
functions in Word program as well. They are GetSetting and
SaveSetting. These functions provide better safety for your data
against loss or corruption since the data is stored in a predefined
Registry location that is exclusively for VBA's use. No need to worry
about permissions. Here is an example...

'This only needs to be run once to initialize the Registry entries
SaveSetting "DocTracker", "DocNum", "Counter"

'This return the Counter value. If it has not been set, it defaults to
1.
Dim Counter As Integer
DocNum =GetSetting("DocTracker", "DocNum", "Counter", "1")

'Increment and Save the new Count
Counter = Counter + 1
SaveSetting "DocTracker", "DocNum" Str(Counter)

Sincerly,
Leith Ross

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
Reading contents Fiona Excel Discussion (Misc queries) 3 June 28th 07 02:56 AM
Reading Contents of a Directory Nigel Excel Programming 2 December 5th 05 05:57 PM
reading contents of a file Christopher Brooks[_3_] Excel Programming 2 June 14th 04 09:06 PM
Browsing to URL and reading contents Mike[_49_] Excel Programming 9 November 20th 03 07:53 PM


All times are GMT +1. The time now is 01:20 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"