LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default External Files


I have several workbooks that several users each have a personalized
copy of. Each workbook opens the file txt.dat(used a simple name for
testing) and reads in the number and populates cell B3 with that
number. It then increments the number by one deletes the file and
re-creates the file writing the new number.

I need all of the workbooks to reference this file to get a unique
number from 1-99999. Is there a way to do this with out getting
errors?

With this code if 2 users run the macro at the same time it locks the
file.




Code:
--------------------
Sub GetGNumb()
Dim gnum As Long

On Error GoTo ErrHandler1
Open "x:\txt.dat" For Input As #1
Input #1, gnum
Range("B3").Activate
ActiveCell.FormulaR1C1 = gnum
Close #1
gnum = gnum + 1
If gnum 99999 Then
gnum = 1
End If

On Error GoTo ErrHandler2
Kill "x:\txt.dat"

On Error GoTo ErrHandler3
Open "x:\txt.dat" For Append As #1
Write #1, gnum
Close #1
Exit Sub

ErrHandler1:
MsgBox ("1")
Close #1
Exit Sub
ErrHandler2:
MsgBox ("2")
Close #1
Exit Sub
ErrHandler3:
MsgBox ("3")
Close #1
End Sub

--------------------


--
nicole0904
------------------------------------------------------------------------
nicole0904's Profile: http://www.excelforum.com/member.php...o&userid=31774
View this thread: http://www.excelforum.com/showthread...hreadid=547237

 
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
Linking to external files Mike Excel Worksheet Functions 1 May 28th 10 04:23 PM
Links to external files Shades Excel Discussion (Misc queries) 3 May 31st 09 01:53 AM
Using External Files BennyK87 Excel Discussion (Misc queries) 2 October 20th 08 06:18 PM
Hyperlinking to External Files Rebecca New Users to Excel 2 October 27th 07 02:42 AM
References to external XLS files goto_guy Excel Discussion (Misc queries) 1 January 17th 06 04:34 PM


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