?
Solved

run excel macro in shared workbook

Posted on 2011-09-29
8
Medium Priority
?
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

770 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