?
Solved

run excel macro in shared workbook

Posted on 2011-09-29
8
Medium Priority
?
509 Views
Last Modified: 2012-05-12
Hi Gents,

I am trying to run a macro in a shared workbook but the macro fails. If the workbook is "un -shared" then there are no issues at all.
The macro fails I think because I used the ActiveSheet. syntax and probably excel cannot determine which one is the active sheet as multiple instances are open at any given time.
I get run time error '1004' saying the" this command is not allowed on a shared workbook" etc.

Any idea how to get around this?

I am just trying to import some data in the workbook sheet with that macro and this operation has to be done while excel is in shared mode.

Any help would be greatly appreciated
Sub AA_Importandupdatedata()
'Sub Import_Data_friday()
'
' Import_Data_friday Macro
' Macro recorded 25/09/2011 by Admin
'
Columns("BK:BM").Select
    Selection.ClearContents
'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Carina_DWOR\ExportData\Friday.txt", Destination:=Range("BK1"))
        .Name = "Monday"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = xlWindows
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .Refresh BackgroundQuery:=False
    End With
    
Range("BK1").Select
Dim rng
Dim sCell
Dim Startcell
Do
sCell = ActiveCell.Value
Startcell = ActiveCell.Address

 ActiveCell.Offset(0, 1).Select
 Selection.Copy
 Range(sCell).Select
  
 Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
 False, Transpose:=False
 Range(Startcell).Select
 ActiveCell.Offset(1, 0).Select
 Loop Until IsEmpty(ActiveCell.Offset(0, 1))
 Range("C5").Select
End Sub

Open in new window

0
Comment
Question by:Latzi_Marian
  • 4
  • 3
8 Comments
 
LVL 50
ID: 36818846
Hello,

Shared workbooks should be avoided. They cause all kinds of trouble and will eventually become corrupt. VBA, worksheet protection and shared workbooks don't play well together.

The unanimous advice of advanced Excel users world-wide is not to use shared workbooks. Excel was not designed for simultaneous multi-user access. If you need such functionality, you should migrate to a database like Access or SQL.

Sorry, that's probably not what you want to hear, but shared workbooks are impossible to troubleshoot, since they can become corrupt at any time and will not necessarily show consistent behaviour.

cheers, teylyn
0
 

Author Comment

by:Latzi_Marian
ID: 36818897
You are right .This is not what I wanted to hear at all. I know that excel hasn't been designed for a multiuser environment and it's very limited if used in such way. Unfortunately I will have to put up with it as the customer is simply not prepared to upgrade to a web based environment.

I actually process all the information which I want to display on that excel sheet in a SQL database using SP's and DTS's and output a flat file which should be "grabbed" by the excel macro and displayed.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36890159
In addition to what teylyn said, your specific issue here is trying to add a querytable. You cannot do that (in code or manually) in a shared workbook.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Latzi_Marian
ID: 36890514
Well you can but it's a very long way around . I did actually told the people involved in this that doing it in Excel is just looking for trouble and wasting time. I will try to do it in Access. That should be ok I think. What's your thoughts?

Obviously doing it in a web based environment would be the best but I have to do it in such a way that users can interact with the code behind easily,modify code,add pages ,etc . Access is what they are prepared to upgrade to.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36890518
Access should be fine, assuming you don't have hundreds of users accessing the data simultaneously.
0
 

Author Comment

by:Latzi_Marian
ID: 36890597
No no. The maximum number of users at any given time would not exceed 8. I think it's going to be ok.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 1500 total points
ID: 36890601
OK, Access should cope with that no problem.
0
 

Author Closing Comment

by:Latzi_Marian
ID: 37693897
decided to go with access
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question